Created
May 13, 2013 10:08
-
-
Save debasishg/5567328 to your computer and use it in GitHub Desktop.
regex interpolation fails ..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Apples-MacBook-Pro:~ debasishg$ scala | |
Welcome to Scala version 2.10.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_45). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> :paste | |
// Entering paste mode (ctrl-D to finish) | |
implicit class RContext(sc: StringContext) { | |
def r = | |
new util.matching.Regex( | |
sc.parts.mkString(""), | |
sc.parts.tail.map(_ => "x"): _*) | |
} | |
// Exiting paste mode, now interpreting. | |
defined class RContext | |
scala> "database:[table1,table2]" matches """(\w+)(:\[(\w+)(,(\w+))*\])?""" | |
res0: Boolean = true | |
scala> :paste | |
// Entering paste mode (ctrl-D to finish) | |
"database:[table1,table2]" match { | |
case r"""(\w+)(:\[(\w+)(,(\w+))*\])?""" => true | |
case _ => false | |
} | |
// Exiting paste mode, now interpreting. | |
res1: Boolean = false | |
scala> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this works ..