Regex pattern
Date Regex (ISO 8601) — free online tester
Match ISO 8601 dates (YYYY-MM-DD) and optionally times in any text — the format JSON APIs, databases, and logs use.
The pattern
\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:?\d{2})?)?/gHow it works
ISO 8601 is the de-facto standard for dates in machine-readable formats: 2024-05-20. This regex matches the date portion and (optionally) an "T HH:MM:SS" time with an optional "Z" or numeric timezone offset, so it handles both bare dates and full timestamps emitted by APIs.
When to use it
- ▸Extract dates from JSON / API logs
- ▸Find timestamps in log files
- ▸Validate date form fields before parsing
- ▸Migrate datestamps in scraped data
Tip
This pattern matches the shape but doesn't validate that the month is 1–12 or that February has fewer than 30 days. Use new Date() to validate after extraction.
Try it on this input
Event date: 2024-05-20 Created: 2024-05-20T14:30:00Z Updated: 2024-05-20T14:30:00.123-05:00 Birthday: 1990-01-15 Yesterday: 2024-03-08 Not dates: 24-05-20, 2024/05/20, May 20 2024, 99-99-99
What this pattern doesn't catch
- ⚠Matches malformed dates like 2024-99-99 (month 99 doesn't exist)
- ⚠Doesn't catch other date formats (DD/MM/YYYY, Month Day, Year, etc.)
- ⚠For strict validation, use a date parser after the match
More regex patterns
Email Regex
A practical email-validation regex that catches the 99% case without choking on every RFC edge case.
URL Regex
Extract every http(s) URL from a block of text — captures protocol, domain, path, query string, and fragment.
Phone Number Regex
Match US / Canada phone numbers in every common written format — with or without country code.
IPv4 Regex
Strictly match IPv4 addresses — rejects out-of-range octets like 256.0.0.1 that simpler patterns let through.
UUID Regex
Strict UUID pattern — validates version (1–7) and variant nibbles so random hex strings don't pass.
Credit Card Regex
Match credit-card numbers from major networks (Visa, Mastercard, Amex, Discover) for extraction or redaction.
Full Regex Tester →
Cheatsheet · pattern builder · cross-language translation · replace · explain · history
