Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
Python

r"
(?P<Date>(?:(?:(?P<Day>\d{1,2})[ /\.]+)?(?P<Month>January|February|March|April|May|June|July|August|September|October|November|December|\d{1,2})[ /\.]+)?(?P<Year>\d{4}|(?(Month)\d{2}|(?P<Age>\d{2}))))\b
"
gmi

Description

matches strings like: "01/04/2023", "14/May/24" and "20" (age). WARNING: for american dates swap day and month! Groups: Date - the whole date Day - day Month - month Year - year (4 or 2 digits) Age - if the string is just one number (Ex. "18"), matches the same as year

Submitted by OlgPok - 7 months ago (Last modified 7 months ago)