Regular Expressions 101

Community Patterns

date pattern

0

Regular Expression
Python

r"
(?=\b(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec|\d{4}|\d{1,2}))\w*[\t\ \\\/\.\,\;\:\-\+\_]+(\d{1,2}|jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)\w*[\t\ \\\/\.\,\;\:\-\+\_]+(\d{4}|\d{1,2})\w*\b
"
gi

Description

This regex can read dates YYYY/MM/DD, dd/mm/yy, Month dd YYYY, YYYY Month dd where Month is the literal description of the month (jan, feb, mar, ..., dec). Use the ignore case flag. It has three capture groups. The regex doesn't handle the sequence logic, that has to be managed later on the captured groups.

Possible mishap occurs when presented with a sequence with two consecutive moths: Month - Month YYYY Although this may be interpreted as an interval between two months. The logic is left for later.

Submitted by anonymous - 7 years ago