PatternRegex

Match an ISO 8601 timestamp

Pull full ISO timestamps out of logs and API payloads — date, T, time, optional milliseconds, and a required Z or offset so half-timestamps don't match.

Last updated

Patterng
\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})
Open in Regex Tester & Builder

Matches

  • 2026-09-04T18:30:00Z
  • 2026-09-04T18:30:04.250+05:30
  • 2026-09-04T02:00:00-08:00

Doesn’t match

  • 2026-09-04 18:30:00
  • 2026-09-04T18:30Z

Why it’s written this way

The shape is rigid on purpose: date, the literal T, a full HH:MM:SS, optional fractional seconds, then a REQUIRED zone — Z or an ±HH:MM offset. Requiring the zone is what separates a machine timestamp from a human "2026-09-04 18:30" that means whatever the writer's wall clock meant.

Edge cases to know

  • Field ranges aren't checked (month 13 passes) — pair with the YYYY-MM-DD pattern's groups if you need that, or parse with a date library after extracting.
  • Space-separated timestamps (common in Postgres logs) don't match — swap the T for [T ] to accept both.
  • Compact ISO without separators (20260904T183000Z) is valid ISO 8601 but out of scope here.

Related in Patterns