ISO 8601 — the canonical format
Always prefer YYYY-MM-DD and ISO 8601 timestamps when you control the format. The regex is trivial:
- Date:
\d{4}-\d{2}-\d{2} - Time:
\d{2}:\d{2}:\d{2} - Datetime:
\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:?\d{2})?
Common ambiguous formats
05/04/2026: is this May 4 (US) or April 5 (most of the world)? Regex can't tell. Don't accept ambiguous formats. Force ISO 8601, or accept multiple unambiguous formats explicitly.
If you must parse various formats, write multiple patterns and try each in order:
1. ISO: \d{4}-\d{2}-\d{2}
2. US slash: \d{1,2}/\d{1,2}/\d{4}
3. EU dot: \d{1,2}\.\d{1,2}\.\d{4}
4. Long: (Jan|Feb|...)\s+\d{1,2},?\s+\d{4}
Validation vs parsing
Regex tells you the SHAPE matches. It doesn't tell you the date is REAL. 2026-02-30 matches the pattern but Feb 30 doesn't exist. Real validation: datetime.strptime(s, fmt) in Python, new Date(s) in JS (then check !isNaN), time.Parse in Go.
Extracting dates from prose
For "find dates in this paragraph," use anchored alternation: \b(\d{4}-\d{2}-\d{2}|\d{1,2}/\d{1,2}/\d{4})\b. Be conservative — false positives in date extraction are common.