Python (re)

ISO 8601 Date-Time in PY

Match full ISO 8601 date-times with timezone offset or Z suffix (e.g. 2024-01-15T14:30:00Z).

Try it in the PY tester →

Pattern

regexPY
\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+\-]\d{2}:?\d{2})   (flags: g)

Python (re) code

pyPython
import re

pattern = re.compile(r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+\-]\d{2}:?\d{2})")
input_text = "2024-01-15T14:30:00Z"
for m in pattern.finditer(input_text):
    print(m.group(0))

Stdlib `re` module — no third-party dependency. Works on Python 3.6+.

How the pattern works

Date YYYY-MM-DD, literal T, time HH:MM:SS, optional fractional seconds, then either Z or a ±HH:MM / ±HHMM offset.

Examples

Input

2024-01-15T14:30:00Z

Matches

  • 2024-01-15T14:30:00Z

Input

2024-03-01T09:00:00.123+05:30

Matches

  • 2024-03-01T09:00:00.123+05:30

Input

2024-01-15

No match

Same pattern, other engines

← Back to ISO 8601 Date-Time overview (all engines)