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

1 Answer

0 votes
import scala.util.matching.Regex

object Main {
  def main(args: Array[String]): Unit = {
    val str = "Scala programming language 'scales' with you from 'small' to 'large applications'"
    
    val regex = new Regex("'([^']*)'")
    
    val matches = (regex findAllIn str).matchData.map(_.group(1)).toList

    matches.foreach(println(_))
  }
}


/*
run:

scales
small
large applications
 
*/

 



answered Feb 13, 2025 by avibootz
...