I’m somewhat in difficulty. (I’m pro in regexps but not much used them in scala/java).
I have numeric string of 11 chars in length, need just last 10, so:
val Pattern = """(\d{10})$""".r
"79283767219" match {
case Pattern(m) => m
}
It gives MatchError, but why?! What have I misunderstood?
Because you have 11 digits, not 10. You can set “10 and more” with
{10,}. To match only end of the string you need to explicitly specify full pattern:Update: until you’re on Scala 2.10 and you can use Daniel’s
unanchoredyou can workaround it like so: