I want to match IP range using a Python regex.
For Ex. the google bot IP range as follow
66.249.64.0 - 66.249.95.255
re.compile(r"66.249.\d{1,3}\.\d{1,3}$")
I can not figure out how to do this? I found this one done using Java.
I want to match IP range using a Python regex.
For Ex. the google bot IP range as follow
66.249.64.0 - 66.249.95.255
re.compile(r"66.249.\d{1,3}\.\d{1,3}$")
I can not figure out how to do this? I found this one done using Java.
You can use this:
re.compile(r"66\.249\.(?:6[4-9]|[78]\d|9[0-5])\.\d{1,3}$")
if you are motivated you can replace \d{1,3} by :
(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)
Explanation:
A regex engine doesn't know what a numeric range is. The only way to describe a range is to write all the possibilities with alternations:
6[4-9] | [78][0-9] | 9[0-5]
6 can be followed by 4 to 9 --> 64 to 69
7 or 8 can be followed by 0 to 9 --> 70 to 89
9 can be followed by 0 to 5 --> 90 to 95