Skip to content

Instantly share code, notes, and snippets.

@dwins
Created June 24, 2010 14:40
Show Gist options
  • Select an option

  • Save dwins/451535 to your computer and use it in GitHub Desktop.

Select an option

Save dwins/451535 to your computer and use it in GitHub Desktop.
scala> val Title = """(Mrs?).*""".r
Title: scala.util.matching.Regex = (Mrs?).*
scala> "Mr. Belvedere" match {
| case Title(title) => println("hey there " + title)
| case _ => println("who are you?");
| }
hey there Mr
scala> val TitleName = """(Mrs?)(.*)""".r
TitleName: scala.util.matching.Regex = (Mrs?)(.*)
scala> "Mr. Belvedere" match {
| case TitleName(title, name) => println(name + ", " + title)
| case _ => println("who are you?")
| }
. Belvedere, Mr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment