How do you expand one literal of regex into multiple lines?

Viewed 41

For example, I have a regex string:

val myRegex:Regex = "blahblah".r

but if the 'blahblah' is like more than thousand characters long, I want to split them into multiple lines so I can read easier. like so:

val myRegex:Regex = "blah".r
+ "blah".r

this does not work because value unary_+ is not a member of scala.util.matching.Regex. is there a proper way?

1 Answers

One possible solution:

val myRegex:Regex = 
  """a
    |very
    |long
    |pattern
    |"""
      .stripMargin
      .replaceAll("\n", "")
      .r
Related