in reply to Why my Regex doesn't work
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: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Why my Regex doesn't work
by Anonymous Monk on Apr 11, 2017 at 15:28 UTC | |
by Not_a_Number (Prior) on Apr 11, 2017 at 17:25 UTC | |
by flappygoat (Initiate) on Apr 11, 2017 at 17:36 UTC | |
by AnomalousMonk (Archbishop) on Apr 11, 2017 at 18:32 UTC | |
by flappygoat (Initiate) on Apr 11, 2017 at 19:16 UTC | |
by Anonymous Monk on Apr 11, 2017 at 21:44 UTC | |
| |
|
Re^2: Why my Regex doesn't work
by flappygoat (Initiate) on Apr 11, 2017 at 17:34 UTC |