I have two regexes doubleRegex and intRegex defined below:
scala> val doubleRegex = """^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$""".r
doubleRegex: scala.util.matching.Regex = ^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$
scala> val intRegex = """^[-+]?[0-9]*$""".r
intRegex: scala.util.matching.Regex = ^[-+]?[0-9]*$
Now I want to match a bunch of strings to detect their types:
scala> List(".01", "11", "1.34").map{ s =>
s match {
case intRegex() => "INT"
case doubleRegex() => "DOUBLE"
case _ => "NONE"
}
}
res5: List[String] = List(NONE, INT, NONE)
Why does it not print List(DOUBLE, INT, DOUBLE) ?
case intRegex(_*) => "INT"andcase doubleRegex(_*) => "DOUBLE".