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?
In reply to My regex is too greedy! by hans_moleman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |