Last active
April 19, 2018 19:42
-
-
Save tyrcho/7b54ee27cd6601afd1c4bca17fce5faf to your computer and use it in GitHub Desktop.
Free Spacing Demo in Scala (add comments to your Regex)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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