Skip to content

Instantly share code, notes, and snippets.

@seanparsons
Created April 11, 2011 20:47
Show Gist options
  • Save seanparsons/914305 to your computer and use it in GitHub Desktop.
Save seanparsons/914305 to your computer and use it in GitHub Desktop.
Easy parsing using regexes and pattern matching.
// The variable data could easily be an Iterator from scala.io.Source instance, it will work just the same.
val data = List("Food,Count","Cake,9","Biscuits,2","Cookie,10")
val Parser = """([^,]+),(\d+)""".r
val entries = data.collect{case Parser(food,count) => (food, count.toInt)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment