I was just wondering if there is a simple way of doing this. i.e. Replacing the occurrence of consecutive characters with the same character.
For eg: - if my string is \
This should do it:
var regex = new Regex("(.)\\1+"); var str = "something likeeeee!! tttthhiiissss"; Console.WriteLine(regex.Replace(str, "$1")); // something like! this
The regex will match any character (.) and \\1+ will match whatever was captured in the first group.
(.)
\\1+