in reply to Re^2: Negating a regexp
in thread Negating a regexp

It is just what OP asked for. If OP wanted to match more or less then:

s/(.*ing)((?!bob|fred|bill)\w+?)(more|less)/$1HIT$3/

does the trick.

Note that OP says:

Im getting stuck specifying 'not' - OK with a caracter class, ( ie ^some chars ) - but not when using parenthesis to define multiple 'words'

DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^4: Negating a regexp
by ikegami (Patriarch) on Jan 31, 2006 at 22:56 UTC
    Nope, doesn't work.
    #!/usr/bin/perl -w use strict; while (<DATA>) { s/(.*ing)((?!bob|fred|bill)\w+?)(more|less)/$1HIT$3/; print $_; } __DATA__ somestringbilless
    outputs
    somestringbilless
    and not
    somestringHITless

      which is actually correct (bill is rejected remember). Try somestringtedless instead (ted is not rejected - lucky ted)


      DWIM is Perl's answer to Gödel

        I didn't say it never works. I know it works for "ted", but it doesn't work for "bil". "bil" doesn't match /bob|fred|bill/ so it should be changed to "HIT".

        [^chars] means "something that isn't 'c', 'h', 'a', 'r' or 's'". What you posted doesn't necessarily mean "something that isn't 'bob', 'fred' or 'bill'". (It depends on what bob, fred, bill and more really are.)

        Update: Added "necessarily".