How can I match any amount of numbers and exactly 1 letter (the valid letters being d, m, y to signify date unit)
e.g. Valid
- 1d
- 30m
- 1232y
e.g. Invalid
- 1dd
- 30mm
- 1232yyy
I’ve tried a few things like [1-9]\b[a-zA-Z]\b and [1-9][a-zA-Z]
>Solution :
If the letter should be at the end
\b\d+[dmy]\b
To not match only zeroes like 00m
\b(?!0+[dmy]\b)\d+[dmy]\b
Note that [1-9] will not match a zero so 30m will not match in that case.