in reply to How to use a negative backreference in regex?

test =~ /^(.)..(?!\1).$/

Replies are listed 'Best First'.
Re^2: How to use a negative backreference in regex?
by gone2015 (Deacon) on Feb 28, 2009 at 13:36 UTC

    Indeed. And the reason [^\1] doesn't work is... well because within a character class \1 means 1, not the contents of the capture buffer 1. Which is a long way of saying it doesn't work because it doesn't work (however plausible it may look).

Re^2: How to use a negative backreference in regex?
by larryk (Friar) on Mar 02, 2009 at 22:01 UTC
    thanks - it's been a while :)

    I eventually ended up with the following:

    my $unique = qr/^(.)(?!\1) (.)(?!\1|\2) (.)(?!\1|\2|\3) .$/x;
       larryk                                          
    perl -le "s,,reverse killer,e,y,rifle,lycra,,print"