Advertisement

Pattern library / Dates & Time

Regex to Match an ISO 8601 DateTime

Log lines, API payloads and analytics exports all stamp events as ISO 8601: 2026-10-28T14:30:00Z. This pattern accepts the practical forms — date, T or space separator, seconds optional, fractional seconds, and a trailing Z or numeric offset — while staying RE2-compatible.

The pattern
^[0-9]{4}-[0-9]{2}-[0-9]{2}[T ][0-9]{2}:[0-9]{2}(:[0-9]{2}(\.[0-9]+)?)?(Z|[+-][0-9]{2}:?[0-9]{2})?$
Load this pattern into the tester →

How the pattern works

Test it: match & no-match examples

Every row is loaded straight into the tester — click Try to see the match live:

InputResultWhy
2026-10-28T14:30:00ZMatchfull form with ZTry →
2026-10-28 14:30Matchspace separator, no secondsTry →
2026-10-28T14:30:00.123+07:00Matchfraction + offsetTry →
2026-10-28T14:30MatchT separator, minutes onlyTry →
28/10/2026 14:30No matchwrong date shapeTry →
2026-10-28T25:00:00ZNo matchhour must be 00-23Try →

Where to use it

JavaScript

const re = /^[0-9]{4}-[0-9]{2}-[0-9]{2}[T ][0-9]{2}:[0-9]{2}(:[0-9]{2}(\.[0-9]+)?)?(Z|[+-][0-9]{2}:?[0-9]{2})?$/;
re.test('2026-10-28T14:30:00Z'); // true

Bash / grep (logs)

grep -E '^[0-9]{4}-[0-9]{2}-[0-9]{2}[T ][0-9]{2}:[0-9]{2}(:[0-9]{2}(\.[0-9]+)?)?(Z|[+-][0-9]{2}:?[0-9]{2})?' app.log

BigQuery (RE2)

SELECT ts FROM logs
WHERE REGEXP_CONTAINS(ts, r'^[0-9]{4}-[0-9]{2}-[0-9]{2}[T ][0-9]{2}:[0-9]{2}(:[0-9]{2}(\.[0-9]+)?)?(Z|[+-][0-9]{2}:?[0-9]{2})?$')

Common mistakes

Test this pattern on your own data
Paste it into the free tester with your real strings — nothing leaves your browser.
Open the regex tester →

FAQ

What date-time formats does this pattern match?

ISO 8601 basics: YYYY-MM-DD, T or space, HH:MM with optional seconds, optional fractional seconds, and an optional trailing Z or +hh:mm / -hh:mm offset.

Why does my pattern fail on 2026-10-28T14:30:00.123456Z?

It should not — the fractional part is (\.[0-9]+), which accepts any number of digits. Paste it in the tester to see which segment fails.

Does this work in GA4 and BigQuery?

Yes — the pattern is pure character classes, groups and alternation, all valid RE2 syntax used by BigQuery REGEXP_CONTAINS and GA4.

Regex to Match Date (YYYY-MM-DD) — Test & Copy · Time Regex (HH:MM / HH:MM:SS) — 24-Hour Match · Log Level Regex — Match INFO / WARN / ERROR Lines

For GA4-specific patterns, see the GA4 regex cheat sheet, the page path regex guide, the event filter regex guide, the GA4 regex match types, the custom channel grouping guide and RE2 vs PCRE. Browse the full regex pattern library.