Regular Expressions:
Using: Use in a typical Scala match statement:
Defining: Just add a ".r" after a normal string:
val regEx = "apple*".r
Using: Use in a typical Scala match statement:
val name = ....
name match {
case regEx => // do your processing here
case entry => // like default, possibly throw an error
}
Grouping:
val zipMatch = "(\\d+)-(\\d+)"
val zip = "12345-1234"
zip match {
case regEx(num1, num2) => // num1 == 12345, num2 == 1234
case entry => // do nothing
}
No comments:
Post a Comment