in reply to stupid question about regexp - not matching a word

Option A: Remove the word from your sentence:
s/\babc\s+//;
Option B: Print only lines without "abc" in them:
print unless /\babc\b/;
Note that the use of \b indicates that there should be a "word-boundary" there. This prevents accidental matches of things like "abcd" or "cbabc".

Option C: Check for something that isn't "abc":
print if /(\w+) nevermind/ && $1 ne "abc";
You could get fancy with look-behind assertions or embedded code, if you desire. See: perlre
print if /(?<!abc) nevermind/;
I think this last one is what you were trying for.

Replies are listed 'Best First'.
Re: Re: Negative Look-behind Assertion
by december (Pilgrim) on Jul 15, 2002 at 22:12 UTC

    I know about look-behind assertions, but I was wondering if there would be a way to do it wihtout... it looks like a common, simple thing, _not_ matching a word...

    But if look-behind assertions are the only solution, then I'll use them.

    I'm not interested in the other solutions, since they require a code change, and... well, it's a bit working around the problem that I wanted to know.

    Thanks!