Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Regex: negative look ahead

by Anonymous Monk
on Apr 10, 2012 at 11:21 UTC ( #964311=note: print w/ replies, xml ) Need Help??


in reply to Regex: negative look ahead

This is because you did not understood the regular expressions at the fundamental level.

.*?
zero chars -> true -> after the current position is not (?!....) -> true -> return true

Use something like:

my $string = "ERROR blah license will expire"; if ($string =~ /^ERROR\b.+?(?:Error processing Cancel Execution|licens +e will expire)\b/m) { print "NOT MATCHED\n"; } else { print "MATCHED\n"; }
or:
if ($string =~ /^ERROR\b/m and $string !~ /\b(?:Error processing Cance +l Execution|license will expire)\b/) { print "MATCHED\n"; } else { print "NOT MATCHED\n"; }


Comment on Re: Regex: negative look ahead
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://964311]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (11)
As of 2014-09-19 06:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (132 votes), past polls