How to get rid of duplicates in regex

Posted by Emmanuel Smith on Stack Overflow See other posts from Stack Overflow or by Emmanuel Smith
Published on 2010-06-10T13:19:10Z Indexed on 2010/06/10 13:22 UTC
Read the original article Hit count: 326

Filed under:
|
|

Suppose I had a string, "cats cats cats and dogs dogs dogs."

What regular expression would I use in order to replace that string with,"cats and dogs." i.e. removing duplicates. The expression however must only remove duplicates that follow after each other. For instance:

"cats cats cats and dogs dogs dogs and cats cats and dogs dogs"

Would return:

"cats and dogs and cats and dogs"

© Stack Overflow or respective owner

Related posts about c#

Related posts about regex