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

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -