Regular Expression for Range (2-16)
With delimiters (out of habit): /^([2-9]|1[0-6])$/
The regex itself is just: ^([2-9]|1[0-6])$
Use the python package regex_engine
for generating regular expressions for numerical ranges
You can install this package with pip
.
pip install regex-engine
from regex_engine import generator
generate = generator()
regex = generate.numerical_range(2, 16)
print(regex)
^([2-9]|1[0-6])$
You can also generate regexes for floating point and negative ranges.
from regex_engine import generator
generate = generator()
regex1 = generate.numerical_range(5, 89)
regex2 = generate.numerical_range(81.78, 250.23)
regex3 = generate.numerical_range(-65, 12)
^([2-9]|1[0-6])$
will match either a single digit between 2 and 9 inclusive, or a 1 followed by a digit between 0 and 6, inclusive.
^([2-9]|1[0-6])$
(Edit: Removed quotes for clarification.)