I am trying to parse IP address from a string:
>>> import re
>>> input_str = '''
kjhdkjfh shfkjdsh shfk 1.1.1.1 kaseroi 1.1.1.1 jsoiu 1.1.1.1
1
1
11
123
132132.23213.213213.123213
23.23.23.23 2321321.33.3.3.3 3.3..3.3.3.3.3.
3.3.3.3.3.3
3.3.3.3
34.5.6.7
agdi 123213.44.4.5 12.12.12.12
'''
>>>
>>>
>>> pattern = r"\b(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9]?[0-9])\b"
>>> re.findall(pattern, input_str)
['1.1.1.1', '1.1.1.1', '1.1.1.1', '23.23.23.23', '33.3.3.3', '3.3.3.3', '3.3.3.3', '3.3.3.3', '34.5.6.7', '12.12.12.12']
>>>
But the valid IP list is:
['1.1.1.1', '1.1.1.1', '1.1.1.1', '23.23.23.23', '3.3.3.3', '34.5.6.7', '12.12.12.12']
Is there anything wrong with regex?