fcaw1 has asked for the wisdom of the Perl Monks concerning the following question:
Hi There I was wondering if you could advise why the following look ahead regex is not working properly. I would not expect the string to match because of the negative look ahead: CODE:
#!/app/perl-5.8/bin/perl my $string = "ERROR blah license will expire"; print `/app/perl-5.8/bin/perl -version` . "\n\n"; if ( $string =~ /(ERROR.*?(?!(Error processing Cancel Execution|licens +e will expire)))/ ){ print "MATCHED\n"; } else { print "NOT MATCHED\n"; }
RESULT:
$ ./regex.pl This is perl, v5.8.3 built for sun4-solaris Copyright 1987-2003, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using `man perl' or `perldoc perl'. If you have access to + the Internet, point your browser at http://www.perl.com/, the Perl Home Pa +ge. MATCHED
Many thanks for your help! Andy
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex: negative look ahead
by JavaFan (Canon) on Apr 10, 2012 at 12:49 UTC | |
|
Re: Regex: negative look ahead
by halfcountplus (Hermit) on Apr 10, 2012 at 11:42 UTC | |
by johngg (Canon) on Apr 10, 2012 at 12:43 UTC | |
by fcaw1 (Initiate) on Apr 10, 2012 at 12:32 UTC | |
by brx (Pilgrim) on Apr 10, 2012 at 14:37 UTC | |
|
Re: Regex: negative look ahead
by Anonymous Monk on Apr 10, 2012 at 11:21 UTC |