Reputation: 3838
val login = "login user=(.*), token=(.*)".r
"login user=SapHana_dummy token=dummy" match {
case login(user, token) =>
println("success")
}
This code always throws MatchError. Instead of printing "success" as intended. Why?
Upvotes: 0
Views: 134
Reputation: 51330
Because your pattern expects a comma, here:
login user=(.*), token=(.*)
^
Which is not in the input text.
Also, to minimize backtracking, I'd use an ungreedy quantifier here:
login user=(.*?) token=(.*)
Upvotes: 3