How to extract all the substrings between single quotation marks in Kotlin

1 Answer

0 votes
fun main() {
    val str = "Kotlin is a 'cross-platform', 'statically typed', 'general-purpose' high-level"
    
    val regex = "'([^']*)'".toRegex()
    
    val matches = regex.findAll(str).map { it.groupValues[1] }.toList()
    
    for (s in matches) {
        println(s)
    }
}


   
/*
run:

cross-platform
statically typed
general-purpose
 
*/

 



answered Feb 13, 2025 by avibootz
...