I entered less than 10 and it come out true. How come? Isn't the range suppose to be between 10 and 99? Anything less than 10 or above 99 should come back false. Can someone explain to me if I am missing something here?
CodePudding user response:
This really depends on your regex.
[1-9][0-9] wil only accept 10-99 for example.
The first digit needs to be in the range of 1 through 9, while the second also is allowed to be a 0
If you would use \d then a 0 is always allowed.
CodePudding user response:
[10-99] includes 1, 0 to 9, and 9, which simply means all digits are included. When hyphen is used inside square brackets, it creates a range between two characters. In your case, those two characters are 0 and 9.
CodePudding user response:
Regex is made for pattern matching (searching for character sequences in strings). It is not god in interpreting text (like numbers).
Your [10-99] regex is actually looking for characters:
1- or a number between
0-9 - or
9
Consider using another tool - Regex is not a good choice for numbers.
