DevTools
Back to Regex Tester

Date Format (YYYY-MM-DD) Regex Pattern

Match and validate ISO 8601 date format (YYYY-MM-DD) using regex. Includes month and day range validation.

The Pattern

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

How It Works

TokenMeaning
\d{4}Exactly 4 digits for the year
-Literal dash separator
(?:0[1-9]|1[0-2])Month: 01-09 or 10-12
-Literal dash separator
(?:0[1-9]|[12]\d|3[01])Day: 01-09, 10-29, or 30-31

Test Cases

2024-01-15Match
2024-12-31Match
2025-06-01Match
2024-13-01No match
2024-00-15No match
2024-01-32No match

Code Examples

javascript
const dateRegex = /\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])/g;
const text = "Events on 2024-01-15, 2024-12-31, and invalid 2024-13-01";
const matches = text.match(dateRegex);
console.log(matches); // ["2024-01-15", "2024-12-31"]
python
import re
date_regex = r'\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])'
text = "Events on 2024-01-15, 2024-12-31, and invalid 2024-13-01"
matches = re.findall(date_regex, text)
print(matches)  # ['2024-01-15', '2024-12-31']

Common Use Cases

Related Patterns

Want to test this pattern with your own data?

Try this pattern in Regex Tester →