Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Can't match negated words.

by Abigail-II (Bishop)
on Jun 24, 2004 at 12:44 UTC ( #369322=note: print w/replies, xml ) Need Help??

in reply to Can't match negated words.

If you just want to match a line where a particular word doesn't appear in, !~ does the trick. But if "not this word" is part of a regular expression, the !~ will not do it. Instead, you basically have to "progress carefully", looking ahead on each step on your way. That is, match a character (any character) after you've concluded it doesn't start a forbidden word. If no character in the (sub)string you match doesn't start a forbidden word, no forbidden words will be in the matched string. How do you check? Use negative lookahead:


Replies are listed 'Best First'.
Re^2: Can't match negated words.
by perlgags78 (Acolyte) on Jun 24, 2004 at 12:52 UTC
    Hi folks, Thanks for all the replies!! This is great. I'm used to forums that take ages or never get back to you.. Abigail, ye've nailed it. That's exactly what I'm looking for, where "not throw" is part of the expression. I'm not familiar with the look ahead stuff but I've a couple of places with examples and I'll look at them. Incidentally are there any online resources you guys could recommend? Thanks again everyone, Mark.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2021-12-05 14:19 GMT
Find Nodes?
    Voting Booth?
    R or B?

    Results (31 votes). Check out past polls.