Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
ECMAScript (JavaScript)

/
^\/?[+-]?P?([0-9]+[Yy])?([0-9]+M)?([0-9]+[Dd])?[Tt]?([0-9]+[Hh])?([0-9]+m|(?:[0-9]+m?(?![0-9]+[Ss])))?([0-9]+[Ss])?$
/

Description

Parses date-time duration strings [+-][P]1y2M3d4h5m6s, where 'm' is the dafault. Like this, where {} contains list of capturing groups: 21 - parsed as {,,,,21,} 2y2s - parsed as {2,,,,,2}

Submitted by mbonaci - 9 years ago