5

I have the following regex, that I would like to pattern match in Scala 2.13.
The regex:

\/brokers\/ids\/\d{1,}$

The following string, that is going to be validate:

scala> ("echo dump" #| "nc localhost 32773" #| "grep brokers").!!
res2: String =
"       /brokers/ids/1
"

How can I do it in Scala 2.13?

Krzysztof Atłasik
  • 21,985
  • 6
  • 54
  • 76
softshipper
  • 32,463
  • 51
  • 192
  • 400

1 Answers1

13

Scala 2.13 introduced interpolated string patterns, so you could avoid using regex and just do:

"/brokers/ids/1" match {
  case s"/brokers/ids/$ids" => ids //returns 1
}
Krzysztof Atłasik
  • 21,985
  • 6
  • 54
  • 76