-
-
Save lachie/306355 to your computer and use it in GitHub Desktop.
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
delimiter = "[-/.]+" | |
century_prefix = "(?:19|20)" | |
under_ten = "(?:0[1-9]+)" | |
ten_to_twelve = "(?:1[012]+)" | |
ten_and_under_thirty = "(?:[12]+[0-9]+)" | |
thirties = "(?:3[01]+)" | |
pattern = %r[ | |
( | |
#{century_prefix}[0-9]{2} # year e.g. 1901, 2036 | |
) | |
#{delimiter} | |
( | |
#{under_ten} | |
| | |
#{ten_to_twelve} | |
) | |
#{delimiter} | |
( | |
#{under_ten} # e.g. 01, 09 | |
| | |
#{ten_and_under_thirty} # e.g. etc | |
| | |
#{thirties} | |
) | |
]x # <- the magickal x; extended mode - whitespace is ignored. Instead, use \s to match whitespace. | |
if "2010-02-17"[pattern] | |
year, month, day = $1, $2, $3 | |
# Insert multi-million dollar idea here | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment