import re
ip = "10.20.30.40 this is an ip. 20.30.40.50.100 this is not ip"
def checkip(ip):
pat = "\d+\.\d+\.\d+\.\d+"
ips = re.findall(pat, ip)
print(ips)
checkip(ip)
output: ['10.20.30.40', '20.30.40.50'] --> here second one is not an ip. but it it picking part of the string.
When I tried the pattern as "^\d+.\d+.\d+.\d+$" I'm not getting empty list.
I don't want second string to be picked, as it is not an ip address. I want to grep only ip address. Not sure what I'm missing and how to debug this. Can someone please help here.