I'm looking to validate a string that has any number of digits followed by a specific character, for example:
"1w 3d 5h 3m" and "32d 5h 3m"
I'm using the following regex at the moment: /\d+[wdhm]\z/ but this is not working if a string contains a letter that I don't want, for example:
"3pp 2h 35m" and "2d 5qq 3m"
The only allowed letters in the string can be "w", "d", "h" and "m" and must be in that order if once is present, for example "2d 35m" is acceptable but "3h 1w" is not because it's in the wrong order.
^(\d+w )?(\d+d )?(\d+h )?(\d+m)$