How do you write a regular expression that matches a numeric range from 0 or 000 to 180 ?
The regex [0-9] matches single-digit numbers 0 to 9. [1-9][0-9] matches double-digit numbers 10 to 99. Something like ^[2-9][1-6]$ matches 21 or even 96! Any help would be appreciated.
Regex is faster for large string than an if (perhaps in a for loops) to check if anything matches your requirement.
Definition and Usage. The [0-9] expression is used to find any character between the brackets. The digits inside the brackets can be any numbers or span of numbers from 0 to 9. Tip: Use the [^0-9] expression to find any character that is NOT a digit.
I don't think regex is the right choice for this. Have you tried parsing the value? If you have to use regex I would match \d{1,3}
parse the string and then validate the number in code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With