Token-by-token breakdown
| Token | Meaning | Example |
|---|---|---|
^ |
Anchor: asserts position at start of the string | Start of '2023-10-05T14:30:00Z' |
\d |
Digit character class (0-9) | Any digit like '2' in '2023' |
{4} |
Quantifier: exactly 4 times | Matches '2023' in '2023-10-05T14:30:00Z' |
- |
Literal hyphen character | The '-' in '2023-10-05T14:30:00Z' |
\d |
Digit character class (0-9) | Any digit like '1' in '10' |
{2} |
Quantifier: exactly 2 times | Matches '10' in '2023-10-05T14:30:00Z' |
- |
Literal hyphen character | The '-' in '2023-10-05T14:30:00Z' |
\d |
Digit character class (0-9) | Any digit like '0' in '05' |
{2} |
Quantifier: exactly 2 times | Matches '05' in '2023-10-05T14:30:00Z' |
T |
Literal 'T' character separating date and time | The 'T' in '2023-10-05T14:30:00Z' |
\d |
Digit character class (0-9) | Any digit like '1' in '14' |
{2} |
Quantifier: exactly 2 times | Matches '14' in '2023-10-05T14:30:00Z' |
: |
Literal colon character | The ':' in '14:30:00Z' |
\d |
Digit character class (0-9) | Any digit like '3' in '30' |
{2} |
Quantifier: exactly 2 times | Matches '30' in '2023-10-05T14:30:00Z' |
: |
Literal colon character | The ':' in '14:30:00Z' |
\d |
Digit character class (0-9) | Any digit like '0' in '00' |
{2} |
Quantifier: exactly 2 times | Matches '00' in '2023-10-05T14:30:00Z' |
(?: |
Non-capturing group start (JavaScript flavor) | Start of '(?:Z|[+-]\d{2}:?\d{2})' |
Z |
Literal 'Z' character for UTC timezone | The 'Z' in '2023-10-05T14:30:00Z' |
| |
Alternation (OR operator) | Separates 'Z' and '[+-]\d{2}:?\d{2}' |
[+-] |
Character class matching '+' or '-' | The '+' in '+05:30' or '-' in '-0800' |
\d |
Digit character class (0-9) | Any digit like '0' in '05' |
{2} |
Quantifier: exactly 2 times | Matches '05' in '+05:30' |
: |
Optional literal colon character (due to :?) | The ':' in '+05:30' |
? |
Quantifier: 0 or 1 times (makes colon optional) | Allows '+' in '+0530' |
\d |
Digit character class (0-9) | Any digit like '3' in '30' |
{2} |
Quantifier: exactly 2 times | Matches '30' in '+05:30' |
) |
Non-capturing group end | End of '(?:Z|[+-]\d{2}:?\d{2})' |
$ |
Anchor: asserts position at end of the string | End of '2023-10-05T14:30:00Z' |
Matches
2023-10-05T14:30:00Z1999-12-31T23:59:59+00:002000-01-01T00:00:00-08002025-06-15T12:45:30+0530
Does not match
2023-10-5T14:30:00Z2023-10-05T14:30:002023-10-05T14:30:00+25:002023-10-05T14:30:00Z2023-10-05T14:30:00+05:3
Common pitfalls
- Forgetting the 'T' separator between date and time
- Incorrect timezone offsets (e.g., +25:00 is invalid)
- Missing leading zeros in month/day/hour/minute/second (e.g., '2023-5-5T5:5:5Z')
- Including spaces or other characters after the timezone
- Using capturing groups instead of non-capturing groups for alternation
Performance notes
The pattern is linear in complexity with no nested quantifiers, so catastrophic backtracking is not a concern. Anchors (^ and $) ensure the entire string is validated, preventing partial matches. For very large inputs, ensure the regex is applied to the entire string rather than searching within it.