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

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

Replies are listed 'Best First'.
Re^5: Negating a regexp
by GrandFather (Saint) on Jan 31, 2006 at 23:00 UTC

    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".

        Ah yes, I see what you mean. My eye didn't notice that it was billess rather than billless. Tricky!


        DWIM is Perl's answer to Gödel