I'm trying to build a regex to match timesheet hours entry where user enters his hours in the format 20h 50m.
In this format, the user can either enter hours only 20h, or minutes only 50m or both hours and minutes 20h 50m.
Sample matches
45m
1h
2h 45m
The numbers can be anything other than 20 or 50.
I came up with this regex ((([0-9]+h)\s([0-9]+m))|([0-9]+h)|([0-9]+m)){1}, which is long and I'm trying to reduce it.
So I tried different solution: ((\d+h)?([\s]*(\d+m))?) https://regex101.com/r/ZEBsle/1/ .But the issue with this solution is that it matches empty strings and doesn't match patterns like 2h 45m.
How can I modify the last regex so it can match the following formats?
45m
1h
2h 45m