regex - How do I find a pattern like 252.63.71.62 in a text in Python with re(gex)? -
i have webpage, text using resources module in python. but, i'm not getting it, how pattern of numbers 126.23.73.34 document , extract out using re module?
you can use regex ips d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}
text = "126.23.73.34"; match = re.search(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', text) if match: print "match.group(1) : ", match.group(0) if looking complete regex ipv4 addresses can find appropriate regex here.
to restrict 4 numbers in ip address 0-255, can use 1 taken source above:
(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)
Comments
Post a Comment