Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

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:



Comment on Re: Can't match negated words.
Download Code
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
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 making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2015-03-29 01:40 GMT
Find Nodes?
    Voting Booth?

    When putting a smiley right before a closing parenthesis, do you:

    Results (629 votes), past polls