Reputation: 19
I need to match a string which has to begin with any number and followed by zero or one occurrence of 'w' or 'm' character. E.g. 123
, 321w
or 231m
'^[0-9]+$' works fine for just the number checking.
I guess something along the lines of [wm]{0,1}
must be added to check for 0 or 1 occurrence of w or m?
Upvotes: 0
Views: 995
Reputation: 115212
Use the following regex
/^\d+[wm]?$/
^
and $
- anchors for start and end position
\d+
- match any digit combination
[wm]?
- match optional w
or m
at the end
Upvotes: 2