Python Practice › RegEx Programs › Program 6
Extract dates
Write a Python program to extract dates in DD-MM-YYYY format and print them as YYYY-MM-DD.
Output
2026-11-15 2026-12-01
Approach
- Capture the three parts and reorder them.
Solution
import re text = "Sprint 1 ends 15-11-2026, release on 01-12-2026."for d, m, y in re.findall(r"(\d{2})-(\d{2})-(\d{4})", text): print(f"{y}-{m}-{d}")Output
2026-11-15 2026-12-01
Learn the concept
New to this topic? Read the lesson, then come back.