How to pattern match in scala 2.13?

天涯浪子 提交于 2019-12-24 01:17:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!