Regex below recognize "[-][[dd.]HH:]mm[:ss[.fffffff]]" pattern and use named groups:
(?:(?<ne>-))?(?:(?:(?<dd>0*[0-9]+)[.])?(?:(?<HH>0*[2][0-3]|0*[1][0-9]|0*[0-9])[:]))?(?<mm>(?<=:)0*[0-5]?[0-9]|0*[5-9]?[0-9](?=[:]))(?:[:](?<ss>0*[0-5]?[0-9](?:[.][0-9]{0,7})?))?
C# Code:
/// <summary>Time Span Standard regular expression.</summary>
/// <remarks>
/// Minutes are mandatory with required colon from left or right.
/// Pattern: [-][[dd.]HH:](:mm|mm:)[:ss[.fffffff]]
/// </remarks>
public const string TimeSpanStandard =
@"(?:(?<ne>-))?" +
@"(?:(?:(?<dd>0*[0-9]+)[.])?(?:(?<HH>0*[2][0-3]|0*[1][0-9]|0*[0-9])[:]))?" +
@"(?<mm>(?<=:)0*[0-5]?[0-9]|0*[5-9]?[0-9](?=[:]))" +
@"(?:[:](?<ss>0*[0-5]?[0-9](?:[.][0-9]{0,7})?))?";
Note: This pattern treats 'dd.HH' as an invalid format. This works for me, because I use this regex to find and replace TimeSpan in JSON strings and support of 'dd.HH' format could wrongly pick up normal numbers.
Regex value example:
-01.23:59:30.999999 - ✔
Match 1 0-19 -01.23:59:30.999999
Group ne 0-1 -
Group dd 1-3 01
Group HH 4-6 23
Group mm 7-9 59
Group ss 10-19 30.999999
Regex Pass:
01.02:03:04.05 - ✔
01.02:03:04 - ✔
01.02:03 - ✔
02:03:04.05 - ✔
03:04.05 - ✔
02:03 - ✔
02:03:04 - ✔
Regex Fail:
1.03:04.05 - ✗
04.05 - ✗