So I need to get hours, minutes and seconds out of entries like these:
- 04:43:12
- 9.43.12
- 1:00
- 01.04
- 59
- 09
The first two is hours, minutes and seconds. Next to is minutes and seconds. Last two is just seconds.
And I came up with this regexp, that works..:
\A(?<hours>\d{1,2})(?::|\.)(?<minutes>\d{1,2})(?::|\.)(?<seconds>\d{1,2})\z|\A(?<minutes>\d{1,2})(?::|\.)(?<seconds>\d{1,2})\z|\A(?<seconds>\d{1,2})\z
But it is ugly, and I want to refactor it down to not be 3 different expressions (mostly just to learn). I tried this:
\A(?:(?<hours>\d{1,2})(?::|\.){0,1})(?:(?<minutes>\d{1,2})(?::|\.){0,1})(?:(?<seconds>\d{1,2}){0,1})\z
But that does not work - minutes and seconds sometimes get screwed up. My brain is hurting, and I can't figure out, what I am doing wrong.