in reply to search pattern not terminated
This does not capture all you wanted but perhaps you can build on this:
... balance of code (Update: ...as corrected in other nodes and restoring the full original string to $log/$s)#!/usr/bin/perl use strict; use warnings; my $log=q<10.25.95.100 ab - [05/Aug/2003:12:00:30 -0700] "GET /creativ +e/2|2127274-1>; # note 1 (re above) # print "\$log is $log \n"; # note 2 if ( $log =~ / (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}) # capture IP digits \s[a-z]{2,2}\s-\s\[ # match but don't capture spa +ce, dash, space (\d+\/[A-Z][a-z]{2,2}\/\d{4,4}) # capture the date : # don't capture the perlimina +ry colon (\d+:\d+:\d+\s-\d{4,4}) # capture time with colons &a +mp; GMT offset (.*) # dot-slash deprecated, but c +apture to end /x ) { # extended notation, end cond +it, print print "\$1=$1, \$2=$2, \$3=$3, \$4 = $4 \n"; # note 3 } else { print "no matches\n"; } # note 4
1 "$s" may be less than clear, a few hundred lines later; use a meaningful name for the $var
2 I read this as OP's simple test to make sure the assignment above worked.
3 It would be better to make this
print "IP = $1, DATE = $2, TIME= $3"and so on, if you're merely testing your regex
4 added the conditional: ALWAYS test captures before trying to use them
|
|---|