Reputation: 370
What is the range of | operator in a regex? and why? how can I control the range of this operator? So that it does not compare 1 digit before it with one digit after it, but 2,3 or more digits before with 2,3 or more digits after. example:
\d\d(0[1-9])|(1[0-2])\d\d
But by parentheses I mean sticking those 2 numbers together
Upvotes: 0
Views: 153
Reputation: 706
You should use |
in these ()
brackets, and if not it works for all the pattern, for yours the wrong was using |
or OR
operator without a bracket and because of that it matched all of the left part or all of the right part of the pattern:-
Yours:-
\d\d(0[1-9])|(1[0-2])\d\d
Solution:-
\d\d((0[1-9])|(1[0-2]))\d\d
Upvotes: 1