I'm having problems getting a regex to work.
Basically, given two search parameters ($search1 and $search2), it
should allow me to filter a log file such that lines with the $search1
string in are printed, unless the $search2 string is also in that line
somewhere (either before or after $search1).
I'm creating my regex like this:
$compiled_regex = qr/^(?!.*$search2)$search1(?!.*$search2)/;
I then use it:
while( <> ) {
next if( $_ !~ /$compiled_regex/ );
print $_ . "\n";
}
With the following test data:
2004-02-18 04:06:50 1AtIua-0001Hh-00 -> sy******@foobar.com R=lookuphost T=remot
e_smtp H=mxhost-1.foo.bar [0.0.0.0]
2004-02-19 04:02:02 1AtfNx-0008DC-00 -> sy******@foobar.com R=lookuphost T=remot
e_smtp H=mxhost-1.foo.bar [0.0.0.0]
2004-02-19 04:07:26 1AtfO5-0008Gs-00 -> sy******@foobar.com R=lookuphost T=remot
e_smtp H=mxhost-1.foo.bar [0.0.0.0]
If $search1 is set to 'sysadmin', and search2 is set to '0008Gs',
none of the lines in the data are displayed, whereas I would expect the
first two to be displayed.
With this test data:
foo
foo foo
foo foo foo
foo bar
bar foo
foo bar foo
foo bar bar
bar foo bar
bar foo foo
bar
bar bar
bar bar bar
$search1 set to 'foo', and $search2 set to 'bar', I get the
expected results (foo, foo foo and foo foo foo displayed).
I just can't figure out why nothing is being displayed in my first test case.
My gut instinct is that it's got something to do with the special'ish
characters in the data ('-', '>' etc.), but I'm not sure.
Any thoughts?
J