Regular Expressions 101

Community Patterns

ISO8601 Date Interval

1

Regular Expression
PCRE (PHP <7.3)

/
^(R\d*\/)?P(\d+([\.,]\d+)?Y)?(\d+([\.,]\d+)?M)?(\d+([\.,]\d+)?W)?(\d+([\.,]\d+)?D)?((?!.$)T(\d+([\.,]\d+)?H)?(\d+([\.,]\d+)?M)?(\d+(\.\d+)?S)?)?$
/

Description

ISO8601 Date Interval with support for fractional values and repeating intervals. DOES NOT SUPPORT fixed intervals (e.g. 2016-03-22P3D or 2016-03-22T14:00Z--2016-03-2518:00+02:00). See https://regex101.com/r/iN2zO9/1 for a ISO8601 date time regex.

Submitted by Tobias Marstaller - 8 years ago