Skip to content

Instantly share code, notes, and snippets.

@gmanley
Created August 31, 2012 16:51
Show Gist options
  • Save gmanley/3555759 to your computer and use it in GitHub Desktop.
Save gmanley/3555759 to your computer and use it in GitHub Desktop.
Date Regex
date = '03/27/1992'
year = /(?<year>(20)?(07|08|09|10|11|12))/
month = /(?<month>0[1-9]|1[012])/
day = /(?<day>0[1-9]|\.[1-9]|[12][0-9]|3[01])/
NUMERAL_DATE_REGEX = /#{year}(?<separator>\.|\-|\/|_)?#{month}(\k<separator>)?#{day}/
if match = NUMERAL_DATE_REGEX.match(@file_name)
Date.parse(date).strftime("%y.%m.%d")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment