I wrote the following regexp to match IP address,
x = 'IP is 200.185.24.24'
y = re.findall('([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-2][0-3])\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-5][0-5])\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-5][0-5])\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-5][0-5])',x)
I am getting the following answer,
>>> y
[('200', '185', '24', '2')]
I have 2 questions here,
- Why my mast octet is failing here. Rest works fine.
- When you see my pattern above, I have repeated the same to match 2nd,3rd and 4th octet of an IP address. Is there a easy way to represent this repeated patterns. I guess \d in tcl is for repeat (not sure). I am looking for similar in python.
Appreciate your inputs.