The presentation below should be clear, I don’t know the exact syntax of the regular expression that you are using, so you need to “translate” it into the actual syntax yourself.
your watch
[0-9]{1,2}h
your minutes
[0-9]{1,2}m
your seconds
[0-9]{1,2}(\.[0-9]{1,3})?s
you want everything in order and can omit any of them (wrap with ?
)
([0-9]{1,2}h)?([0-9]{1,2}m)?([0-9]{1,2}(\.[0-9]{1,3})?s)?
this, however, matches things like: 10h30s
valid combinations are hms
, hm
, hs
, h
, ms
, m
and s
or iow, minutes can be skipped, but there are still hours and seconds.
another problem is that if an empty string is given, it matches, since all three ?
make it valid. so you need to get around this somehow. um
looking at @dbaupp h(ms?)?|ms?|s
, you can take above and map:
h: [0-9]{1,2}h m: [0-9]{1,2}m s: [0-9]{1,2}(\.[0-9]{1,3})?s
so you can:
h(ms?)?: ([0-9]{1,2}h([0-9]{1,2}m([0-9]{1,2}(\.[0-9]{1,3})?s)?)? ms? : [0-9]{1,2}m([0-9]{1,2}(\.[0-9]{1,3})?s)? s : [0-9]{1,2}(\.[0-9]{1,3})?s
all those OR'd together give you a big but easily broken regular expression:
([0-9]{1,2}h([0-9]{1,2}m([0-9]{1,2}(\.[0-9]{1,3})?s)?)?|[0-9]{1,2}m([0-9]{1,2}(\.[0-9]{1,3})?s)?|[0-9]{1,2}(\.[0-9]{1,3})?s
which will save you the trouble with empty string and hs
matching.
looking at @ Donal Fellows comment on @ dbaupp's answer, I will also do (h?m)?S|h?M|H
(h?m)?s: (([0-9]{1,2}h)?[0-9]{1,2}m)?[0-9]{1,2}(\.[0-9]{1,3})?s h?m : ([0-9]{1,2}h)?[0-9]{1,2}m h : [0-9]{1,2}h
and when combined, you will get something less than the above:
(([0-9]{1,2}h)?[0-9]{1,2}m)?[0-9]{1,2}(\.[0-9]{1,3})?s|([0-9]{1,2}h)?[0-9]{1,2}m|[0-9]{1,2}h
now we need to find a way to match the .xx
demical view