I have the following string:
text = '10.0.0.1.1 but 127.0.0.256 1.1.1.1'
and I want to return the valid IP addresses, so it should only return 1.1.1.1
here since 256
is higher than 255
and the first IP has too many numbers.
so far I have the following but it doesn't work on the 0-255
requirement.
text = "10.0.0.1.1 but 127.0.0.256 1.1.1.1"
l = []
import re
for word in text.split(" "):
if word.count(".") == 3:
l = re.findall(r"[\d{1,3}]+\.[\d{1,3}]+\.[\d{1,3}]+\.[\d{1,3}]+",word)
Here is a python regex that does a pretty good job of fetching valid IPv4 IP addresses from a string: