Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
Created·2019-11-07 17:01
Flavor·PCRE (Legacy)

/
^P(?!$)(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)W)?(?:(\d+)D)?(?:T(?=\d)(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?)?$
/
gm
Open regex in editor

Description

With lookaround, this regular expression will reject P and PT as invalid duration strings. If your library does not support lookaround, I recommend that you use Full ISO 8601 Duration without lookaround (also in the library) instead, with the caveat that you will need to verify the string is not P or PT, which will be incorrectly accepted.

Submitted by anonymous