This has gotta be something stupid, but I'm wondering if someone can help me out here. The following regex pattern match within a case class match is not working as I would expect. Can someone provide some insight? Thanks.
object Confused {
case class MyCaseClass(s: String)
val WS = """\s*""".r
def matcher(myCaseClass: MyCaseClass) = myCaseClass match {
case MyCaseClass(WS(_)) => println("Found WS")
case MyCaseClass(s) => println(s"Found >>$s<<")
}
def main(args: Array[String]): Unit = {
val ws = " "
matcher(MyCaseClass(ws))
}
}
I would expect the the first case in the pattern match to be the one that matches, but it is not.
This prints
Found >> <<