Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Can't match negated words.

by perlgags78 (Acolyte)
on Jun 24, 2004 at 13:28 UTC ( #369346=note: print w/ replies, xml ) Need Help??

in reply to Can't match negated words.

Hi folks, I may have screwed my original post up. I wanted to simply reply but instead I seem to have deleted the original message. I amended my code as follows

if ($line =~ /(?:(?!throw).)/ ) { debug ("Doesn't contain throw"); }
yet it still printed the statement for the line
//throw OtherException
I've put '.*' at the start and end of the reg exp but it still doesn't see the throw in the throw line. Thanks, Mark.

Comment on Re: Can't match negated words.
Select or Download Code
Replies are listed 'Best First'.
Re^2: Can't match negated words.
by hv (Parson) on Jun 24, 2004 at 14:00 UTC

    First, You haven't duplicated Abigail-II's expression correctly; if you do so, it will work correctly:

    if ($line =~ /^(?:(?!throw).)*$/s) { debug ("Doesn't contain throw"); }

    An alternative formulation, which I find slightly cleaner, is to recast it as a single negative lookahead:

    if ($line =~ /^(?!.*?throw)/) { ... }


      hi Hugo, I see that you've a ? before the throw. What function has this? Is the '?' associated with the .* or the throw? Also I'm having hassle getting return characters to appear in my posts so they kinda look like one line posts. Any ideas? Thanks, Mark.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (10)
As of 2015-11-27 17:26 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (731 votes), past polls