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:
/^(?:(?!throw).)*$/s
Abigail
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Can't match negated words.
by perlgags78 (Acolyte) on Jun 24, 2004 at 12:52 UTC |
In Section
Seekers of Perl Wisdom