title: Regex substitution: Replace texts, not codes
body: <p>I'm trying to solve a quiz of regex for days but still can't get it right. I'm getting so close but still can't get it to pass.</p>
  <h2>Task:</h2>
  <blockquote>
  <p>In an HTML page, replace the text <code>micro</code> with <code>&amp;micro;</code>. Oh, and don't screw up the code: don't replace inside <code>&lt;the tags&gt;</code> or <code>&amp;entities;</code></p>
  </blockquote>
  <h3>Replace</h3>
  <ul>
  <li><code>micro</code> -&gt; <code>&amp;micro;</code></li>
  <li><code>abc micro</code> -&gt; <code>abc &amp;micro;</code></li>
  <li><code>micromicro</code> -&gt; <code>&amp;micro;&amp;micro;</code></li>
  <li><code>&amp;micro;micro</code> -&gt; <code>&amp;micro;&amp;micro;</code></li>
  </ul>
  <h3>Don't touch</h3>
  <ul>
  <li><code>&lt;tag micro /&gt;</code> -&gt; <code>&lt;tag micro /&gt;</code></li>
  <li><code>&amp;micro;</code> -&gt; <code>&amp;micro;</code></li>
  <li><code>&amp;abcmicro123;</code> -&gt; <code>&amp;abcmicro123;</code></li>
  </ul>
  <hr />
  <p><a href="https://regex101.com/r/MDKEmj/1" rel="nofollow noreferrer">I tried this</a> but it fails on the last <code>&amp;micro;</code>, what did I miss? Can someone point out what did I miss? Thanks in advance!</p>
  <h2>What I have tried:</h2>
  <h3>Regex</h3>
  <pre><code>((?:\G|\n)(?:.*?&amp;.*?micro.*?;[\s\S]*?|.*?&lt;.*?micro.*?&gt;[\s\S]*?|.)*?)micro
  </code></pre>
  <h3>Substitution</h3>
  <pre><code>$1&amp;micro;
  </code></pre>