Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
.NET 7.0 (C#)

@"
^P(?!$)(?:(?<years>\d+(?:\.\d+)?)Y)?(?:(?<months>\d+(?:\.\d+)?)M)?(?:(?<weeks>\d+(?:\.\d+)?)W)?(?:(?<days>\d+(?:\.\d+)?)D)?(T(?=\d)(?:(?<hours>\d+(?:\.\d+)?)H)?(?:(?<minutes>\d+(?:\.\d+)?)M)?(?:(?<seconds>\d+(?:\.\d+)?)S)?)?$
"
gmx

Description

Regex for validating ISO 8601:2004E durations, complete with named capture groups.

Submitted by Sakura Akeno Isayeki - 2 years ago