Skip to content

Instantly share code, notes, and snippets.

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 lachie/306355 to your computer and use it in GitHub Desktop.
Save lachie/306355 to your computer and use it in GitHub Desktop.
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