A \n regex backreference is not active in a character class; [^\1] is equivalent to [^1] (Update: Nope. Not quite. See Update below.)
Try:
(note the use of the /x modifier — for clarity only).c:\@Work\Perl\monks>perl -wMstrict -le "my $s = 'CCHHHCHHCHC'; print qq{'$s'}; ;; $s =~ s/(\w) (?!\1). \1/$1$1$1/xgi; print qq{'$s'}; " 'CCHHHCHHCHC' 'CCHHHHHHHHC'
Update: In fact, \1 in a character class is an octal escape sequence:
(no match; nothing printed). Wonderful what you can find out if you actually test stuff.c:\@Work\Perl\monks\flappygoat>perl -wMstrict -le "my $s = qq{\1\x01\o{001}\cA}; print 'match' if $s =~ /[^\1]/; print 'count: ', $s =~ tr/\1//; " count: 4
Give a man a fish: <%-{-{-{-<
In reply to Re: Why my Regex doesn't work
by AnomalousMonk
in thread Why my Regex doesn't work
by flappygoat
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |