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?
In reply to Why my Regex doesn't work by flappygoat
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |