How to match words in a string that are wrapped in curly brackets using RegEx with Scala

1 Answer

0 votes
object CurlyBracketMatcher {
  def main(args: Array[String]): Unit = {
    val str = "This is a {string} with {multiple} {words} wrapped in curly brackets."

    // Define the RegEx pattern
    val regex = "\\{([^}]+)\\}".r

    // Find all matches
    val matches = regex.findAllMatchIn(str).map(_.group(1)).toList

    println(s"Matches: $matches")
  }
}

  
     
/*
run:
  
Matches: List(string, multiple, words)
 
*/

 



answered Mar 18 by avibootz
...