Skip to content

Instantly share code, notes, and snippets.

@p3t0r
Created November 4, 2009 07:26
Show Gist options
  • Save p3t0r/225879 to your computer and use it in GitHub Desktop.
Save p3t0r/225879 to your computer and use it in GitHub Desktop.
// Somple simple examples of using regular expressions in combination with pattern matching in Scala
//
// runs correctly on scala 2.8-nightly and 2.7.6.final
val RegionExpr = """.*?[aieoué][^aieoué](.+)""".r // string after first non-vowel following a vowel
"vergadering" match {
case RegionExpr(matchedGroup) => println("matched group: " + matchedGroup) // prints "gadering"
case _ =>
}
val DateExpr = """(\d{2})\-(\d{2})\-(\d{4})""".r // match dates in format "dd-MM-yyyy"
"01-07-2005" match {
case DateExpr(d,m,y) => println("groups: %s %s %s".format(d,m,y)) // prints "groups: 01 07 2005"
case _ =>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment