PaulDotCom mailing list archives

Re: Better RegEX to find IPs


From: Pat <nutjob.ie () gmail com>
Date: Wed, 1 Dec 2010 22:58:44 +0000

The reason your getting splits is the grouping brackets ()

Remove them from inside the regex

Also pipe is or operator which will cause weirdness

That's provided there the same as c ,egrep  regex

Sorry for short answer phone mail

I'll send you a working one at 11 am gmt tomorrow if your still stuck but
the one in the mail by Carl looks good to me
On 1 Dec 2010 22:47, "Adrian Crenshaw" <irongeek () irongeek com> wrote:
Thanks, but the one they are calling "Accurate" is the same one I'm using
as
best as I can tell. I don't need to split the the octets.

Thanks,
Adrian

On Wed, Dec 1, 2010 at 5:14 PM, teacher1st <teacher1st () bellsouth net>
wrote:

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 listPauldotcom@mail.pauldotcom.comhttp://
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

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

Current thread: