Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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 chilling in the Monastery: (9)
As of 2015-07-31 02:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (274 votes), past polls