Tutorial by Examples

The r method implicitly provided via scala.collection.immutable.StringOps produces an instance of scala.util.matching.Regex from the subject string. Scala's triple-quoted string syntax is useful here, as you do not have to escape backslashes as you would in Java: val r0: Regex = """(...
val re = """\((.*?)\)""".r val str = "(The)(example)(of)(repeating)(pattern)(in)(a)(single)(string)(I)(had)(some)(trouble)(with)(once)" re.findAllMatchIn(str).map(_.group(1)).toList res2: List[String] = List(The, example, of, repeating, pattern, in, a, ...

Page 1 of 1