I searched a lot and can't find the solution for this RegExp (I have to say I'm not very experienced in Reg. Expressions).
I would like to test a number between 1 and 36, excluding 0 and 37 and above.
What I've got so far and almost works (it doesn't accept 17, 18, 19, 27, 28, 29)...
^[1-9]{1}$|^[1-3]{1}[0-6]{1}$|^36$;
Can someone help me please?
Example: Regex Number Range 1-20 Range 1-20 has both single digit numbers (1-9) and two digit numbers (10-20). For double digit numbers we have to split the group in two 10-19 (or in regex: "1[0-9]") and 20. Then we can join all these with an alternation operator to get "([1-9]|1[0-9]|20)".
The regex [0-9] matches single-digit numbers 0 to 9. [1-9][0-9] matches double-digit numbers 10 to 99. That's the easy part. Matching the three-digit numbers is a little more complicated, since we need to exclude numbers 256 through 999.
Python Regex – Get List of all Numbers from String. To get the list of all numbers in a String, use the regular expression '[0-9]+' with re. findall() method. [0-9] represents a regular expression to match a single digit in the string.
Most characters, including all letters ( a-z and A-Z ) and digits ( 0-9 ), match itself. For example, the regex x matches substring "x" ; z matches "z" ; and 9 matches "9" . Non-alphanumeric characters without special meaning in regex also matches itself. For example, = matches "=" ; @ matches "@" .
You know about \d
, right?
^([1-9]|[12]\d|3[0-6])$
Try this in console:
function test() { for(var i = 0; i < 100; i++) { if (/^([1-9]|[12]\d|3[0-6])$/.test(i.toString()) != (i >= 1 && i <=36)) { document.write(i + "fail"); } else document.write(i + "pass"); document.write("<br/>"); } }
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