Last active
January 5, 2017 11:55
-
-
Save misterbailey/42c0a756fba7eaf4d25e6373b177eb99 to your computer and use it in GitHub Desktop.
Regex: retrieve date from string
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
$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&\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