Regex Tester & DebuggerSpecialized Version
🔍

Date Regex Tester

Date regex

//g
Flags:
Examples:

Date Regex Tester

Test and validate date format patterns with regular expressions. Handle various date formats including ISO 8601, US, European, and custom formats.

Common Date Formats

| Format | Example | Pattern | ISO 86012024-12-25\d{4}-\d{2}-\d{2} US12/25/2024\d{2}/\d{2}/\d{4} European25/12/2024\d{2}/\d{2}/\d{4} US short12/25/24\d{2}/\d{2}/\d{2} WrittenDec 25, 2024[A-Z][a-z]{2} \d{1,2}, \d{4} | ISO datetime | 2024-12-25T14:30:00Z | See below |

Date Patterns

``javascript // ISO 8601 date const isoDate = /^\d{4}-\d{2}-\d{2}$/;

// ISO 8601 datetime with timezone const isoDateTime = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?(?:Z|[+-]\d{2}:\d{2})$/;

// US date format (MM/DD/YYYY) const usDate = /^\d{2}\/\d{2}\/\d{4}$/;

// Flexible date (accepts /, -, or .) const flexibleDate = /^\d{2}[-.\/]\d{2}[-.\/]\d{4}$/;

// Date with validation const strictDate = /^(?:0[1-9]|1[0-2])[-\/](?:0[1-9]|[12]\d|3[01])[-\/]\d{4}$/;

// Test isoDate.test('2024-12-25'); // true isoDateTime.test('2024-12-25T14:30:00Z'); // true usDate.test('12/25/2024'); // true `

Strict Date Validation

`javascript // Validate date ranges function validateDateRegex(format) { // Month: 01-12 const month = '(?:0[1-9]|1[0-2])';

// Day: 01-31 (doesn't check month-specific) const day = '(?:0[1-9]|[12]\d|3[01])';

// Year: 1900-2099 const year = '(?:19|20)\d{2}';

const patterns = { 'YYYY-MM-DD': new RegExp(^${year}-${month}-${day}$), 'MM/DD/YYYY': new RegExp(^${month}/${day}/${year}$), 'DD/MM/YYYY': new RegExp(^${day}/${month}/${year}$) };

return patterns[format]; }

const isoStrict = validateDateRegex('YYYY-MM-DD'); isoStrict.test('2024-12-25'); // true isoStrict.test('2024-13-25'); // false (month > 12) isoStrict.test('2024-12-32'); // false (day > 31) `

Extract Dates from Text

`javascript // Find various date formats in text const datePattern = /\b(?:\d{4}[-\/]\d{2}[-\/]\d{2}|\d{2}[-\/]\d{2}[-\/]\d{4}|(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)[a-z]* \d{1,2},? \d{4})\b/gi;

const text = "Meeting on 2024-12-25. Follow up 01/15/2025 or January 20, 2025."; const dates = text.match(datePattern); // ["2024-12-25", "01/15/2025", "January 20, 2025"] `

Date Parsing with Groups

`javascript // Extract date components const dateParser = /^(?\d{4})-(?\d{2})-(?\d{2})$/;

const match = '2024-12-25'.match(dateParser); const { year, month, day } = match.groups; // year: "2024", month: "12", day: "25" ``

Frequently Asked Questions

Can regex validate that a date is real (like Feb 30)?

No, regex can only check format, not calendar validity. 02/30/2024 matches \\d{2}/\\d{2}/\\d{4} but isn't a real date. For true validation, parse the date: const d = new Date(dateStr); return !isNaN(d) && d.toISOString().startsWith(dateStr);

How do I match dates with different separators?

Use a character class for separators: \\d{2}[-/.]\\d{2}[-/.]\\d{4} matches 12-25-2024, 12/25/2024, and 12.25.2024. For consistent separators, use backreference: \\d{2}([-/.])\\d{2}\\1\\d{4} ensures same separator throughout.

Should I use regex or Date parsing for validation?

Use both: regex for format checking (quick rejection of invalid formats), then Date parsing for validity (handles leap years, month lengths). Pattern ^\\d{4}-\\d{2}-\\d{2}$ ensures format, then new Date(str) validates the actual date.

Related Tools

Explore other tools you might find useful:

Related Calculators