Why does this compile?
val regex = raw"a*".r
def matchRegex(str: String): Boolean =
str match {
case regex("abc") => true
case _ => false
}
As you can see, I don't try to extract any values from the string but instead I specify a string in the first case of the match (usually you would do something like regex(_*)
to see if it matches). The method matchRegex
always returns false
but I wonder how this doesn't throw any error not even a runtime error.