flappygoat has asked for the wisdom of the Perl Monks concerning the following question:
Hi everyone. I want to have a regex that matches all occurrences of a letter sandwiched between 2 same letters(the letter in the middle is different than the two outer letters) and changes the middle letter so that all 3 letters are the same. For instance it would change CCHHHCHHCHC into CCHHHHHHHCC. I only work with 3 chars C,H,E but I wrote for a general case, but it won't work the way I want. my regex is
s/(\w)[^\1]\1/$1$1$1/giI don't understand why it matches HHH if I wrote that the middle letter cannot be the same as first. Why is this wrong and how to make it work?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Why my Regex doesn't work
by AnomalousMonk (Archbishop) on Apr 11, 2017 at 14:01 UTC | |
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 flappygoat (Initiate) on Apr 11, 2017 at 17:34 UTC |