PaulDotCom mailing list archives
Re: Better RegEX to find IPs
From: Chris Keladis <ckeladis () gmail com>
Date: Thu, 2 Dec 2010 09:09:33 +1100
On Thu, Dec 2, 2010 at 8:08 AM, Adrian Crenshaw <irongeek () irongeek com>wrote: Hey Adrian,
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:
Everything that looks like an IP, or everything that's a legal IP? In perl i'd match something like \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} (sorry my Python is a bit rusy). But it all depends on your requirements really. Cheers, Chris.
_______________________________________________ Pauldotcom mailing list Pauldotcom () mail pauldotcom com http://mail.pauldotcom.com/cgi-bin/mailman/listinfo/pauldotcom Main Web Site: http://pauldotcom.com
Current thread:
- Better RegEX to find IPs Adrian Crenshaw (Dec 01)
- Re: Better RegEX to find IPs Chris Keladis (Dec 01)
- Re: Better RegEX to find IPs Adrian Crenshaw (Dec 01)
- Re: Better RegEX to find IPs teacher1st (Dec 01)
- Re: Better RegEX to find IPs Adrian Crenshaw (Dec 01)
- Re: Better RegEX to find IPs Chris Frederick (Dec 01)
- Re: Better RegEX to find IPs Pat (Dec 01)
- Re: Better RegEX to find IPs Adrian Crenshaw (Dec 01)
- Re: Better RegEX to find IPs Chris Keladis (Dec 01)