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

I'm not sure I'm reading your question right, but you're wondering why [^(abc)] doesn't match the string abc?

The square brackets enclose an expression that will match one character. The construct you show will match anything other than (, ), a, b, or c. I think that's what your description is trying to say.

You can get the effect you want in Perl newer than 5.6.1 with a lookbehind assertion: print if /(?<!abc) nevermind/There are other ways to do it, using $PREMATCH, but this will work for fixed strings. More information at perlre, the section about lookbehind.</code>

That is, if I read your question correctly....

Replies are listed 'Best First'.
Re: Re: stupid question about regexp - not matching a word
by december (Pilgrim) on Jul 15, 2002 at 22:15 UTC

    Yes, that's the solution. Is there no way without look-behind assertions? It seems like a common thing to do, 'not match' a expression of grouped letters (i.e. a word).

    Thanks for your answer :)

      Yes, there's the negative look-a-head assertion. ;-)
      /^(?!abc)\w+ something/

      But why are you afraid of look-behind assertions. Asking for a solution to X without using Y, if Y is a reasonable way of solving X should have an explaination of why Y shouldn't be used.

      Abigail