Regular Expressions 101

Community Patterns

date_regex

1

Regular Expression
Python

r"
(?<!\d) (?: [0-9]{4} (?P<sep1>[-/.])? (?: (?:(?(sep1)0?|0)[1-9]|1[0-2]) (?(sep1)(?P=sep1)|) (?:(?(sep1)0?|0)[1-9]|1[0-9]|2[0-8]) |(?:(?(sep1)0?|0)[13-9]|1[0-2]) (?(sep1)(?P=sep1)|) (?:29|30) |(?:(?(sep1)0?|0)[13578]|1[02]) (?(sep1)(?P=sep1)|) (?:31) ) | (?: [0-9]{2} (?: 0[48] |[2468][048] |[13579][26] ) |(?: 0[48] |[2468][048] |[13579][26] )00 ) (?P<sep2>[-/.]?) (?(sep2)0?|0)2 (?(sep2)(?P=sep2)|) (?:29) ) (?!\d)
"
gmx

Description

YYYYMMDD YYYY-MM-DD YYYY.MM.DD YYYY/MM/DD YYYY-M-D YYYY.M.D YYYY/M/D

If the sep[-./] is not given, "0" must appear before a single num. such as 20180203, 20190905. If the sep [-./] is given, the prefix 0 is optional.

Submitted by anonymous - 4 years ago (Last modified 3 months ago)