Regular Expressions 101

Community Library Entry

0

Regular Expression
PCRE (PHP <7.3)

/
\b([0][1-9]|[1-9]|1[012])([\/-]|\s)([0][1-9]|[0-9]|1[0-9]|2[0-9]|3[0-1])([\/-]|\s)\d{2,4}
/
g

Description

Finds dates in a variety of formats with years being 2 or 4 digits. Iterations include a space, a hyphen, or a / for the separator. MM-DD-YY(YY), MM DD YY, or MM/DD/YY, and allows the month and days to have a preceding 0 such as 01/01/2021 as well as 1/1/2021. ([/-]|\s) is the separating group and a period can be added for a format such as 1.1.2021. No parameters were placed on the year, just 2 or four digits.

Submitted by Spodg13 - 3 years ago