Token-by-token breakdown
| Token | Meaning | Example |
|---|---|---|
^ |
Anchor: start of string | Start of input |
(?: |
Non-capturing group start | Grouping for alternation |
(?: |
Non-capturing group start | Grouping for 31-day months |
31 |
Literal '31' | Day 31 |
(\/|-|\.) |
Capture group 1: separator (/, -, or .) | Separator character |
(?:0?[13578]|1[02]) |
Non-capturing group: months with 31 days (1,3,5,7,8,10,12) | Months like 1, 01, 3, 12 |
\1 |
Backreference to capture group 1 (separator) | Same separator as first |
| |
Alternation (OR) | Either 31-day or 29/30-day month |
(?:29|30) |
Non-capturing group: days 29 or 30 | Day 29 or 30 |
(\/|-|\.) |
Capture group 2: separator (/, -, or .) | Separator character |
(?:0?[1,3-9]|1[0-2]) |
Non-capturing group: months with 29/30 days (1-9,10,11,12) | Months like 2, 02, 4, 11 |
\2 |
Backreference to capture group 2 (separator) | Same separator as second |
)) |
Non-capturing group end (twice) | End of 31/29/30-day month group |
(?:(?:1[6-9]|[2-9]\d)?\d{2}) |
Non-capturing group: year (1600-9999) | Year like 1999, 2024 |
$ |
Anchor: end of string | End of input |
| |
Alternation (OR) | Either first pattern or leap year February |
^ |
Anchor: start of string | Start of input |
(?:29(\/|-|\.)0?2\3 |
Non-capturing group: Feb 29 with separator | Feb 29 with separator |
(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00)))) |
Non-capturing group: leap year validation (divisible by 4, not by 100 unless by 400) | Years like 2000, 2024, 2028 |
$ |
Anchor: end of string | End of input |
| |
Alternation (OR) | Either previous patterns or standard date |
^ |
Anchor: start of string | Start of input |
(?:0?[1-9]|1\d|2[0-8]) |
Non-capturing group: days 1-28 | Day 1-28 |
(\/|-|\.) |
Capture group 4: separator (/, -, or .) | Separator character |
(?:(?:0?[1-9])|(?:1[0-2])) |
Non-capturing group: months 1-12 | Months like 1, 01, 12 |
\4 |
Backreference to capture group 4 (separator) | Same separator as fourth |
(?:(?:1[6-9]|[2-9]\d)?\d{2}) |
Non-capturing group: year (1600-9999) | Year like 1999, 2024 |
$ |
Anchor: end of string | End of input |
Matches
31/01/202430-04-202315.05.199929/02/202029-02-200001/01/160028.12.9999
Does not match
31/04/202430-02-202329/02/202332/01/202400/01/202415/13/202429/02/190029.02.2100
Common pitfalls
- Fails to validate years below 1600 (e.g., 1599 is accepted but invalid in this pattern)
- Does not handle years with leading zeros beyond single-digit (e.g., 01600 is invalid)
- Separator must be consistent throughout the date (e.g., 31/01-2024 fails)
- Does not account for dates with extra whitespace or formatting
- Leap year validation may not cover all edge cases (e.g., 2100 is not a leap year but may be accepted if not properly validated)
Performance notes
High risk of catastrophic backtracking due to nested quantifiers and alternations. Avoid using this pattern on untrusted input without strict validation. Consider simplifying or breaking into smaller patterns.