I’m wondering if it’s possible to compare values in regexps with the regexp system in Python. Matching the pattern of an IP is easy, but each 1-3 digits cannot be above 255 and that’s where I’m a bit stumped.
I’m wondering if it’s possible to compare values in regexps with the regexp system
Share
You need to check the allowed numbers in each position. For the first optional digit, acceptable values are 0-2. For the second, 0-5 (if the first digit for that part is present, otherwise 0-9), and 0-9 for the third.
I found this annotated example at http://www.regular-expressions.info/regexbuddy/ipaccurate.html :