I'd like to make a reglar expression which checks date digit e.g. 1 through 31.
I think it has three patterns : [0-9]
, [12][0-9]
, 3[01]
.
But I don't know how to make them as one regex with |(or) operator.
Anybody has idea for this?
I'd like to make a reglar expression which checks date digit e.g. 1 through 31.
I think it has three patterns : [0-9]
, [12][0-9]
, 3[01]
.
But I don't know how to make them as one regex with |(or) operator.
Anybody has idea for this?
Updated:
([0-2][0-9]|(3)[0-1])
Hope this answer your question
What you need is alternation and a group to make the pattern local. Just use a |
within the capture group (a|b)
or non-capturing group (?:a|b)
:
([1-9]|[12][0-9]|3[01])