hayio
8/29/2015 - 11:56 PM

Regex group and lookaround matching.

Regex group and lookaround matching.

val string = "one493two483three"
val pattern = """two(\d+)three""".r
pattern.findAllMatchIn(string) foreach {
   m => println(m.group(1))
   // prints 483
}

//-------------------------------------------

val string = "one493two483three"
val pattern = """(?<=two)\d+(?=three)""".r
pattern.findAllIn(string).foreach(println)
// also prints 483