title: Replace with RegExp only outside tags in the string
body: <p>I have a strings where some html tags could present, like</p>
  
  <pre><code>this is a nice day for bowling &lt;b&gt;bbbb&lt;/b&gt;
  </code></pre>
  
  <p>how can I replace with RegExp all <strong>b</strong> symbols, for example, with <strong>:blablabla:</strong> (for example) but <strong>ONLY</strong> outside html tags?</p>
  
  <p>So in that case the resulting string should become</p>
  
  <pre><code>this is a nice day for :blablabla:owling &lt;b&gt;bbbb&lt;/b&gt;
  </code></pre>
  
  <p><strong>EDIT:</strong> I would like to be more specific, based on the answers I have received. So first of all I have just a string, not DOM element, or anything else. The string may or may not contain tags (opening and closing). The main idea is to be able to <strong>replace anywhere in the text except inside tags</strong>. For example if I have a string like</p>
  
  <pre><code>not feeling well today :/ check out this link &lt;a href="http://example.com"&gt;http://example.com&lt;/a&gt;
  </code></pre>
  
  <p>the regexp should replace <strong>only</strong> first <code>:/</code> with real smiley image, but should not replace second and third, because they are inside (and part of) tag. Here's an example snippet using the regexp from one of the answer.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var s = 'not feeling well today :/ check out this link &lt;a href="http://example.com"&gt;http://example.com&lt;/a&gt;';
  var replaced = s.replace(/(?:&lt;[^\/]*?.*?&lt;\/.*?&gt;)|(:\/)/g, "smiley_image_here");
  document.querySelector("pre").textContent = replaced;</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;pre&gt;&lt;/pre&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>It is strange but the <a href="https://regex101.com/r/sI0nW9/2" rel="nofollow">DEMO</a> shows that it captured the correct group, but the same regexp in replace function seem not to be working.</p>