Extract dates

EasyRegEx Programs · 6 of 20

Write a Python program to extract dates in DD-MM-YYYY format and print them as YYYY-MM-DD.

Advertisement
Output
2026-11-15
2026-12-01

Approach

  1. Capture the three parts and reorder them.

Solution

Python
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.

More regex programs

← All 20 RegEx Programs

Leave a Comment