Skip to content

Instantly share code, notes, and snippets.

@tyrcho
Last active April 19, 2018 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tyrcho/7b54ee27cd6601afd1c4bca17fce5faf to your computer and use it in GitHub Desktop.
Save tyrcho/7b54ee27cd6601afd1c4bca17fce5faf to your computer and use it in GitHub Desktop.
Free Spacing Demo in Scala (add comments to your Regex)
val re = """(?x)
# Match a 20th or 21st century date in yyyy-mm-dd format
# ?x is free-spacing flag to allow #comments, must be right at start of String
(19|20)\d\d # year (group 1)
[- /.] # separator
(0[1-9]|1[012]) # month (group 2)
[- /.] # separator
(0[1-9]|[12][0-9]|3[01]) # day (group 3)
""".r
"1990-02-20" match {
case re(y, m, d) => println(y, m, d)
}
// see https://www.regular-expressions.info/freespacing.html
// try it online @ https://scastie.scala-lang.org/cG09nykWSPG8tRfGhf5CHA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment