Skip to content

Instantly share code, notes, and snippets.

@davidandrzej
Created June 22, 2012 00:57
Show Gist options
  • Select an option

  • Save davidandrzej/2969618 to your computer and use it in GitHub Desktop.

Select an option

Save davidandrzej/2969618 to your computer and use it in GitHub Desktop.
"Manually" extracting the captured groups
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