Regular Expressions 101

Community Patterns

Full ISO 8601 Duration without lookaround

0

Regular Expression
PCRE (PHP <7.3)

/
^P(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)W)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?)?$
/
gm

Description

Without lookaround, this regular expression also accepts P and PT as valid duration strings. If your library supports lookaround, I recommend that you use Full ISO 8601 Duration with lookaround (also in the library) instead, which will also reject P and PT.

Submitted by anonymous - 4 years ago