Skip to content

Instantly share code, notes, and snippets.

@misterbailey
Last active January 5, 2017 11:55
Show Gist options
  • Save misterbailey/42c0a756fba7eaf4d25e6373b177eb99 to your computer and use it in GitHub Desktop.
Save misterbailey/42c0a756fba7eaf4d25e6373b177eb99 to your computer and use it in GitHub Desktop.
Regex: retrieve date from string
$regex = '/(?<date_format_1>(?<day>(?i)\b\s*[0-9]+(?:st|nd|rd|th|)?)
(?<month>(?i)(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sept(?:ember?)|Oct(?:ober)?|Nov(?:ember?)|Dec(?:ember)?))
(?<year>\b\s*20[0-9]{2}))|
(?<date_format_2>(?P>month)(?P>day)(?!\s+-)(?:\s&amp;\s(?P>day))?) |
(?<range_type_1>(?P>month)(?P>day)\s+-\s+(?P>day))
/x';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment