问题
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?
回答1:
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 //return 1
}
来源:https://stackoverflow.com/questions/57089633/how-to-pattern-match-in-scala-2-13