Results 1 to 4 of 4
Hi,
What will be regexp to read IP address for a log file like this. I only need to read the IP addresses.
2011.05.13-14:54:58, EMAILADDRESS, 180.211.51.11, pop3
2011.05.13-14:57:26, EMAILADDRESS, 160.234.47.12, ...
- 05-16-2011 #1Just Joined!
- Join Date
- May 2011
- Posts
- 3
Regexp to read IP
Hi,
What will be regexp to read IP address for a log file like this. I only need to read the IP addresses.
2011.05.13-14:54:58, EMAILADDRESS, 180.211.51.11, pop3
2011.05.13-14:57:26, EMAILADDRESS, 160.234.47.12, pop3
2011.05.13-14:57:54, EMAILADDRESS, 166.22.22.224, imap
2011.05.13-14:57:55, EMAILADDRESS, 172.58.22.154, imap
2011.05.13-15:03:08, EMAILADDRESS, 190.22.120.44, pop3
I've put the email address as EMAILADDRESS because it my 2nd post and not allowed to post URLs'
I've tried this regex, but is not working
'^[a-z]{3}, ([0-9.]* \,)';
Thanks for your help in advance.
- 05-16-2011 #2
This seems to be a comma separated list.
You don´t need a regex, a simple cut will do.
Code:man cut
You must always face the curtain with a bow.
- 05-16-2011 #3Just Joined!
- Join Date
- May 2011
- Posts
- 3
Thanks for your suggestion.
Actually i need the regex as i'm using it in a existing perl script.
- 05-16-2011 #4
a general number would match:
[1-9][0-9]*
thus 4 consecutive numbers split by . would be the ip:
[1-9][0-9]*\.[1-9][0-9]*\.[1-9][0-9]*\.[1-9][0-9]*
which can be simplified to:
(([1-9][0-9]*\.){3}[1-9][0-9]*)
or:
([1-9][0-9]*[\.]?){4}
Please note that you should also put some context into the regex to not match false positives that occur in the rest of the string (like matching the date if one thinks to be funny by writing 2011.05.13.14.54.58 as date time string).
What exactly got into you to match ^[a-z] is to me like a mystery hidden in a riddle wrapped up in an enigma.
... if it's important, let us know!
Last edited by Kloschüssel; 05-16-2011 at 11:29 AM.


Reply With Quote