I have a pipe delimited list of phrases. I would like to remove sequential duplicates using a regex replace/substitution. For example:
dog|cat|cat woman|cat woman|dog|dog
cat|cat|catman|catman|catman|cat woman|cat woman|dog|dogman|doggy
would be transformed into
dog|cat|cat woman|dog
cat|catman|cat woman|dog|dogman|doggy
I am stuck. So far, I am at
((^|\|)([^\|]+))\1+
with a substitution of $1
. But clearly, that does not work, for the output is
dog|cat woman|cat woman|dog
cat|catman|catman|cat woman|dogman|doggy
Thanks for your help