Created
June 22, 2012 00:57
-
-
Save davidandrzej/2969618 to your computer and use it in GitHub Desktop.
"Manually" extracting the captured groups
This file contains hidden or 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
| scala> val myRegex = """Foo=([0-9]+) Bar=([A-Z]+)""".r | |
| myRegex: scala.util.matching.Regex = Foo=([0-9]+) Bar=([A-Z]+) | |
| scala> val m = myRegex.findFirstMatchIn("Foo=123 Bar=ABC").get | |
| m: scala.util.matching.Regex.Match = Foo=123 Bar=ABC | |
| scala> val foo = m.group(1) | |
| foo: String = 123 | |
| scala> val bar = m.group(2) | |
| bar: String = ABC | |
| scala> println("foobar looks like %s-%s".format(foo,bar)) | |
| foobar looks like 123-ABC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment