title: Remove duplicates within consecutive runs of characters
body: <p>I have strings containing lots of duplicates, like this:</p>
  <pre><code>tst &lt;- c(&quot;C&gt;C&gt;C&gt;B&gt;B&gt;B&gt;B&gt;C&gt;C&gt;*&gt;*&gt;*&gt;*&gt;*&gt;C&quot;, &quot;A&gt;A&gt;A&quot;, &quot;*&gt;B&gt;B&quot;, 
       &quot;A&gt;A&gt;A&gt;A&gt;A&gt;*&gt;A&gt;A&gt;A&gt;*&gt;*&gt;*&gt;*&gt;A&gt;A&quot;, &quot;*&gt;C&gt;C&quot;, &quot;A&quot;)
  </code></pre>
  <p>I'd like to remove all <strong>consecutive duplicated upper-case and &quot;*&quot;</strong> characters, so the expected result is this:</p>
  <pre><code>[1] &quot;CBC*C&quot; &quot;A&quot;     &quot;*B&quot;    &quot;A*A*A&quot; &quot;*C&quot;    &quot;A&quot;
  </code></pre>
  <p>I've successfully extracted the duplicated capitals:</p>
  <pre><code>library(stringr)
  unlist(str_extract_all(gsub(&quot;&gt;&quot;, &quot;&quot;, tst), &quot;(.)(?=\\1)&quot;))
  [1] &quot;C&quot; &quot;C&quot; &quot;B&quot; &quot;B&quot; &quot;B&quot; &quot;C&quot; &quot;*&quot; &quot;*&quot; &quot;*&quot; &quot;*&quot;
  </code></pre>
  <p>but am somewhat stuck here. My hunch is that the function <code>which</code>, which returns indices, might be of help but don't know how to implement it in this case.</p>
  <p>Any ideas?</p>
  <p><strong>EDIT</strong>:</p>
  <p>I wasn't that far from the solution myself - just using a <em>negative</em> lookahead (instead of the positive lookahead) does the trick:</p>
  <pre><code>str_extract_all(gsub(&quot;&gt;&quot;, &quot;&quot;, tst), &quot;(.)(?!\\1)&quot;)
  [[1]]
  [1] &quot;C&quot; &quot;B&quot; &quot;C&quot; &quot;*&quot; &quot;C&quot;
  
  [[2]]
  [1] &quot;A&quot;
  
  [[3]]
  [1] &quot;*&quot; &quot;B&quot;
  
  [[4]]
  [1] &quot;A&quot; &quot;*&quot; &quot;A&quot; &quot;*&quot; &quot;A&quot;
  
  [[5]]
  [1] &quot;*&quot; &quot;C&quot;
  
  [[6]]
  [1] &quot;A&quot;
  </code></pre>