hans_moleman has asked for the wisdom of the Perl Monks concerning the following question:
Greetings all.
I'm writing a script to parse syslog messages from a Cisco VPN Concentrator. Each line contains a number of fields, including a "message field". I'm using regular expressions to grab the data I need from these message fields based on the message type.
In one particular case (Administrative user login if you want to know) the lines look like this:
Mar 3 11:29:11 10.20.20.2 8194 03/03/2003 13:15:37.330 SEV=5 AUTH/36 +RPT=29 User [ admin ] Protocol [ Telnet ] attempted ADMIN logon.. St +atus: <ACCESS GRANTED> !
I want to grab the user name from the message string. After using split() to isolate the different fields I want, I tried using a regular expression to get the name:
$user=~s/.+\[[ ]+(.+)[ ]+\].+/$1/;
Unfortunately, this regular expression returns the second element between brackets. In the sample line above, it would return "Telnet". I ended up finding a solution using split :
(undef,$user,undef)=split(/\[ | \]/,$message,3);
Because, as always TMTOWTDI. However I'm curious as to what is wrong with my regular expression. I went to the camel and tried several iterations of the regular expression we see above but no joy. Anyone care to shed some light on the situation?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: My regex is too greedy!
by Mr. Muskrat (Canon) on Mar 05, 2003 at 16:25 UTC | |
|
Re: My regex is too greedy!
by blokhead (Monsignor) on Mar 05, 2003 at 16:28 UTC | |
by Nkuvu (Priest) on Mar 05, 2003 at 17:22 UTC | |
by blokhead (Monsignor) on Mar 05, 2003 at 18:07 UTC | |
by Nkuvu (Priest) on Mar 05, 2003 at 19:50 UTC | |
|
Re: My regex is too greedy!
by kelan (Deacon) on Mar 05, 2003 at 18:12 UTC |