I am currently trying to decipher the appropriate regex for identifying a pattern similar to 2d1h30m10s
, accepting any valid variation such as 1h
, 1h30m
, 30m
, 10s
, or any combination of these. Could regex be the right solution in this scenario?
I have been attempting to comprehend it, yet despite my efforts, all I receive is false
when running various tests:
/^(0?[1-9]|1[0-2][h])([1-6][0-9][m])([1-6][0-9][s])\d$/.test('2d1h10m10s')
/^(0?[1-9]|1[0-2][h])([1-6][0-9][m])([1-6][0-9][s])\d$/.test('10m10s')
/^(0?[1-9]|1[0-2][h])([1-6][0-9][m])([1-6][0-9][s])\d$/.test('10s')
What elements am I overlooking here?