I am trying to find an IP pattern or any similar pattern in a string. for example:
Text_1 = "Hello this ip is valid: 123.22.33.22 , but!" #expect 123.22.33.22
Text_2 = "this could be the second valid ip: 323.123.22.33.22 , but!" #expect 323.123.22.33.22
Text_3 = "third pattern is: 01.002.33.222 , but!" #expect 01.002.33.222
Text_4 = "fourth pattern is: 332.332.222 , but!" #expect 332.332.222
In all cases I need to extract all numbers which are separate by dots and later on evaluate if they are potentially valid or not.
I had a look to this question and this question, but all have some issues!
This is what I found but does not work perfectly as it can't catch the string longer than 4-digit:
import re
re.search(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', s).group()