I want to match the digits before h, m, and s into their respective capture groups. I want to match all 3 groups if possible. If one or two of the other groups are missing then match the last group(s).
As seen in the image below and in this regex101, I have currently a regex of
/(\d+)(?=h)|(\d+)(?=m)|(\d+)(?=s)/g, which matches, for my test string, 12 matches with 1 group in each match.
But I want 7 matches. Where the first match contains 3 groups, the 2:nd to 4:th match contain 2 groups each and the last 3 matches contain 1 group each.
So I want:
- Match 1:
11h22m33s- Group 1:
11 - Group 2:
22 - Group 3:
33
- Group 1:
- Match 2:
11h22m- Group 1:
11 - Group 2:
22
- Group 1:
- Match 3:
11h33s- Group 1:
11 - Group 2:
33
- Group 1:
- Match 4:
22m33s- Group 1:
22 - Group 2:
33
- Group 1:
- Match 5:
11h- Group 1:
11
- Group 1:
- Match 6:
22m- Group 1:
22
- Group 1:
- Match 7:
33s- Group 1:
33
- Group 1:
Edit
The test strings can be contained within other strings! E.g. 08:00 + 11h. See https://regex101.com/r/RWA9Oy/1
