salatconed has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to use variables to hold the regex exppression to make it easier to code, and I'm running into one issue parsing firewall logs.
When I call the same regex variable multiple times the first group returns the correct result but the second one shows part of the first IP address.
-- Sample data Mar 10 07:42:38 DR-FW-1 : %ASA-6-305011: Built dynamic UDP translation from inside:172.28.17.130/3324 to outside(internet-traffic):69.176.102.83/24295
output: re1 -> 172.28.17.130 re2 -> 17. ------------------------------------------ my $Raw_Log = ""; my $re_ipv4 = qr/(([2]([0-4][0-9]|[5][0-5])|[0-1]?[0-9]?[0-9])[.]){3}( +([2]([0-4][0-9]|[5][0-5])|[0-1]?[0-9]?[0-9]))/; # Open file to read lines my $logfile = $ARGV[0]; my $linenum = 0; open(LOGFILEHD, $logfile); while( <LOGFILEHD>){ $Raw_Log = $_; print "$Raw_Log\n"; $Raw_Log =~ /($re_ipv4).*($re_ipv4)/; print "re1 -> $1\n"; print "re2 -> $2\n"; $linenum += 1; } close(LOGFILEHD);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using variable to hold regex expression
by choroba (Cardinal) on Mar 11, 2013 at 23:12 UTC | |
|
Re: Using variable to hold regex expression
by Kenosis (Priest) on Mar 11, 2013 at 23:36 UTC | |
by salatconed (Initiate) on Mar 12, 2013 at 00:05 UTC | |
by AnomalousMonk (Archbishop) on Mar 12, 2013 at 00:35 UTC | |
by Kenosis (Priest) on Mar 12, 2013 at 00:31 UTC |