Created
June 19, 2014 22:34
-
-
Save tlef/4090fca664e400f42c8d to your computer and use it in GitHub Desktop.
Date and time based Regex patterns
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
Pattern for dates and date ranges: | |
/\b((monday|tuesday|wednesday|thursday|friday|saturday|sunday|mon|tue|tues|wed|thu|thur|thurs|fri|sa|sat|su|sun|today|tomorrow|yesterday)|(((january|february|march|april|may|june|july|august|september|october|november|december|ja|jan|fe|feb|mar|ap|apr|jun|jul|au|aug|se|sep|sept|oc|oct|no|nov|de|dec)[ ]([0-3]?[0-9])(st|rd|nd|th)?)([ ]?(20)?([0-9][0-9]))?)(([-]|([ ]+(to|until|til)[ ]+)?)([0-3]?[0-9])(st|rd|nd|th)?)?)|((([3]?[0-1])|([0-2]?[0-9]))[.-\/](([3]?[0-1])|([0-2]?[0-9]))[.-\/]([1-2][0-9])?[0-9][0-9])\b/i | |
Pattern for times (12 and 24h): | |
/\b((0?[1-9]|1[0-2])(:?[0-5][0-9])?(am|pm))|(0?[1-9]|1[0-9]|2[0-3])(((h|:)[0-5][0-9])|h)\b/ | |
Pattern for time ranges: | |
/\b(((((0?[1-9]|1[0-2])(:?[0-5][0-9])?(am|pm))|(0?[1-9]|1[0-9]|2[0-3])(((h|:)[0-5][0-9])|h))((([ ]+)?([-]|(to))([ ]+)?)(((0?[1-9]|1[0-2])(:?[0-5][0-9])?(am|pm)?)|(0?[1-9]|1[0-9]|2[0-3])(((h|:)?[0-5][0-9])|h)))?)|((((0?[1-9]|1[0-2])(:?[0-5][0-9])?(am|pm)?)|(0?[1-9]|1[0-9]|2[0-3])(((h|:)?[0-5][0-9])|h))((([ ]+)?([-]|(to))([ ]+)?)(((0?[1-9]|1[0-2])(:?[0-5][0-9])?(am|pm))|(0?[1-9]|1[0-9]|2[0-3])(((h|:)[0-5][0-9])|h)))))\b/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment