in reply to RegEx: How to negate more than one character?

I recommend reading perlrequick and perlretut to gather some insight on how regular expressions work.

Nevertheless, here's a possible implementation:

my $re = qr/(?:a|b)h/; print 'abcdef' !~ $re; print 'ahcdef' !~ $re; print 'abbhef !~ $re;
yields
1 (0) (0)

Replies are listed 'Best First'.
Re^2: RegEx: How to negate more than one character?
by lokiloki (Beadle) on Mar 25, 2007 at 23:15 UTC
    thanks... but I am looking for the particular negation to be part of a much more complex overall regular expression... i.e., how can i do the negation within the expression itself, rather than relying on !~?

    What I am trying to do is match outermost <% ... %> "brackets" while also handling possible internal pairs of my own unique bracketing system:

    $re = qr{\<\%(?:(?>[^(\<\%|\%\>)]+)|(??{$re}))\%\>};

    I guess what I am looking for is a replacement to the [^(\<\%|\%\>)]+ part above (unless that is correct).

      You can proably use a negatively asserted look ahead: $str =~ m/$pattern(?!ab|cd)$morepattern/;. It is a zero-width pattern, but it might do what you want. It's about half-way through perlre.

      -Paul