ISO 8601 Duration
intermediateMatches ISO 8601 duration strings like P1Y2M3DT4H5M6S.
durationisoperiodtime
Pattern
/P(?:\d+Y)?(?:\d+M)?(?:\d+W)?(?:\d+D)?(?:T(?:\d+H)?(?:\d+M)?(?:\d+(?:\.\d+)?S)?)?/gTry It
0 of 8 strings matched
Explanation
Matches ISO 8601 duration format: P followed by optional year, month, week, day components, then T with optional hour, minute, second (with fractional) components.
Test Strings
Matching
- P1Y2M3D
- PT1H30M
- P1DT12H
- PT0.5S
Non-matching
- 1Y2M
- T1H30M
- duration
- 12345
Language Compatibility
| Language | Support |
|---|---|
| JS | Full support |
| PYTHON | Full support |
| JAVA | Full support |
| PHP | Full support |
| GO | Full support |
Code Snippets
const regex = /P(?:\d+Y)?(?:\d+M)?(?:\d+W)?(?:\d+D)?(?:T(?:\d+H)?(?:\d+M)?(?:\d+(?:\.\d+)?S)?)?/g;
const text = "your text here";
const matches = text.match(regex);
console.log(matches);