PaulDotCom mailing list archives

Re: Better RegEX to find IPs


From: teacher1st <teacher1st () bellsouth net>
Date: Wed, 01 Dec 2010 17:14:09 -0500

Some suggestions here:
http://answers.oreilly.com/topic/318-how-to-match-ipv4-addresses-with-regular-expressions/


On 12/1/2010 4:08 PM, Adrian Crenshaw wrote:
Hi All,
I've Googled around and not had much luck finding something better. I'm trying to parse a file in Python and extract all IPs. Currently I'm using:


IPsInFile = re.findall('(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)',TextBlob)

But this gives me some bad results such as:

.106
.123.102
.128
.143
.144
.186.64
.190
.2
.200.65
.208.7
.214
.24.124.224
.250.23.32
.36.132.142
.73
0.204.35.172
0.36.132.60
0.6.1.32
0.6.1.33
0.64
1.159.84
1.33

Any ideas for a better regular expression to use?

Thanks,
Adrian


_______________________________________________
Pauldotcom mailing list
Pauldotcom () mail pauldotcom com
http://mail.pauldotcom.com/cgi-bin/mailman/listinfo/pauldotcom
Main Web Site: http://pauldotcom.com

_______________________________________________
Pauldotcom mailing list
Pauldotcom () mail pauldotcom com
http://mail.pauldotcom.com/cgi-bin/mailman/listinfo/pauldotcom
Main Web Site: http://pauldotcom.com

Current thread: