in reply to Re: Regex negative word
in thread Regex negative word

Note that your example is not entirely sensible, though. The expression you give must begin with whitespace, so of course it doesn't begin cat. You have to remember that the lookahead is zero-width, so after it, you're in the same position in the string as before it. Perhaps something like
/^(?!cat).*\sdog/
as the most general case to consume the non-cat, before-the-dog portion of the string.

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^3: Regex negative word
by GhodMode (Pilgrim) on Mar 30, 2006 at 15:42 UTC
    You are absolutely right! But, rereading the question, the whitespace and the dog aren't necessary, either. zer just asked for a regex that matches a string which does not begin with cat. So, I think /^(?!cat)/ should do it. That would match any line with a beginning which is not followed by a cat, right?
    --
    -- GhodMode
    
    Blessed is he who has found his work; let him ask no other blessedness.
    -- Thomas Carlyle
      Incidentally, due to my only skimming the replies, I've wasted everyone's time. My apologies to GrandFather who gave the correct answer first.
      --
      -- GhodMode
      
      Blessed is he who has found his work; let him ask no other blessedness.
      -- Thomas Carlyle