Scala capture group using regex

后端 未结 5 928
[愿得一人]
[愿得一人] 2020-12-12 23:42

Let\'s say I have this code:

val string = \"one493two483three\"
val pattern = \"\"\"two(\\d+)three\"\"\".r
pattern.findAllIn(string).foreach(println)
         


        
5条回答
  •  醉话见心
    2020-12-13 00:02

    You want to look at group(1), you're currently looking at group(0), which is "the entire matched string".

    See this regex tutorial.

提交回复
热议问题