PaulDotCom mailing list archives

Better RegEX to find IPs


From: Adrian Crenshaw <irongeek () irongeek com>
Date: Wed, 1 Dec 2010 16:08:29 -0500

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

Current thread: