Skip to content

Instantly share code, notes, and snippets.

@aphexmunky
Created May 19, 2015 14:13
Show Gist options
  • Select an option

  • Save aphexmunky/2ff1d3e56796916a15fa to your computer and use it in GitHub Desktop.

Select an option

Save aphexmunky/2ff1d3e56796916a15fa to your computer and use it in GitHub Desktop.
Pattern matching regex types
val LoglevelPattern = """.*\[(DEBUG|INFO|WARN|ERROR)\].*""".r
LoglevelPattern: scala.util.matching.Regex = .*\[(DEBUG|INFO|WARN|ERROR)\].*
"""1. [INFO] starting system""" match { case LoglevelPattern(level) => level; case other => "OTHER" }
res1: String = INFO
"""1. [WARNING] starting system""" match { case LoglevelPattern(level) => level; case other => "OTHER" }
res2: String = OTHER
"""1. [WARNING] starting system""" match { case LoglevelPattern(level) => level; case other => "OTHER" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment