How to find all double quote substrings in a string with Kotlin

1 Answer

0 votes
fun main() {
    val str = """This is a string with "double-quoted substring1", and "double-quoted substring2" inside."""

    // Regular expression pattern to match substrings within double quotes
    val pattern = Regex("\"([^\"]*)\"")

    // Find all matches
    val matches = pattern.findAll(str)

    // Print each extracted substring using a loop
    for (match in matches) {
        println(match.groupValues[1])
    }
}


   
      
/*
run:

double-quoted substring1
double-quoted substring2
  
*/

 



answered May 13 by avibootz
...