title: Regex to replace reg trademark
body: <p>I need some help with regex:</p>
  
  <p>I got a html output and I need to wrap all the registration trademarks with a <code>&lt;sup&gt;&lt;/sup&gt;</code></p>
  
  <p>I can not insert the <code>&lt;sup&gt;</code> tag in title and <code>alt</code> properties and obviously I don't need to wrap regs that are already superscripted.</p>
  
  <p>The following regex matches text that is not part of a HTML tag:</p>
  
  <pre><code>(?&lt;=^|&gt;)[^&gt;&lt;]+?(?=&lt;|$)
  </code></pre>
  
  <p>An example of what I'm looking for:</p>
  
  <pre><code>$original = `&lt;div&gt;asd&amp;reg; asdasd. asd&lt;sup&gt;&amp;reg;&lt;/sup&gt;asd &lt;img alt="qwe&amp;reg;qwe" /&gt;&lt;/div&gt;`
  </code></pre>
  
  <p>The filtered string should output:</p>
  
  <pre><code>&lt;div&gt;asd&lt;sup&gt;&amp;reg;&lt;/sup&gt; asdasd. asd&lt;sup&gt;&amp;reg;&lt;/sup&gt;asd &lt;img alt="qwe&amp;reg;qwe" /&gt;&lt;/div&gt;
  </code></pre>
  
  <p>thanks a lot for your time!!!</p>