Python (re)

European Date Format (DD/MM/YYYY) in PY

Match European-style dates in DD/MM/YYYY format with valid day (01–31) and month (01–12) ranges.

Try it in the PY tester →

Pattern

regexPY
(?:0[1-9]|[12]\d|3[01])\/(?:0[1-9]|1[0-2])\/\d{4}   (flags: g)

Python (re) code

pyPython
import re

pattern = re.compile(r"(?:0[1-9]|[12]\d|3[01])\/(?:0[1-9]|1[0-2])\/\d{4}")
input_text = "15/01/2024"
for m in pattern.finditer(input_text):
    print(m.group(0))

Stdlib `re` module — no third-party dependency. Works on Python 3.6+.

How the pattern works

Day alternation covers 01–31, month covers 01–12, year is any 4-digit number. Slashes are literal. Does not detect impossible combinations like 31/02/2024.

Examples

Input

15/01/2024

Matches

  • 15/01/2024

Input

31/12/1999

Matches

  • 31/12/1999

Input

32/01/2024

No match

Same pattern, other engines

← Back to European Date Format (DD/MM/YYYY) overview (all engines)