I am trying to capture parts of a multi-line regular expression in Scala. The input has the form:
val input = """some text |begin { | content to extract | content to extract |} |some text |begin { | other content to extract |} |some text""".stripMargin
I tried several possibilities which should receive the text from begin { } blocks. One of them:
val Block = """(?s).*begin \{(.*)\}""".r input match { case Block(content) => println(content) case _ => println("NO MATCH") }
I get NO MATCH . If I omitted \} , the regex looks like (?s).*begin \{(.*) , And it matches the last block, including the unwanted ones } and "some text". I checked my regular expression on rubular.com, as well as on /.*begin \{(.*)\}/m , and it matches at least one block. I thought that when my Scala expression matches the same, I can start using findAllIn to match all the blocks. What am I doing wrong?
I looked at the Scala Regex enable Multiline option , but I was not able to capture all occurrences of text blocks, for example, Seq[String] . Any help is appreciated.
scala regex
Thomas Rawyler
source share