RegExp to search text inside HTML tags
<p>I'm having some difficulty using a RegExp to search for text between HTML tags. This is for a search function to search text on a HTML page without find the characters as a match in the tags or attributes of the HTML. When a match has been found I surround it with a div and assign it a highlight class to highlight the search words in the HTML page. If the RegExp also matches on tags or attributes the HTML code is becoming corrupt.</p>

<p>Here is the HTML code:</p>

<pre><code>&lt;html&gt;
&lt;span&gt;assigned&lt;/span&gt;
&lt;span&gt;Assigned &gt; to&lt;/span&gt;

&lt;span&gt;assigned &gt; to&lt;/span&gt;

&lt;div&gt;ticket assigned to&lt;/div&gt;

&lt;div id="assigned" class="assignedClass"&gt;Ticket being assigned to&lt;/div&gt;

&lt;/html&gt;
</code></pre>

<p>and the current RegExp I've come up with is:</p>

<p>(?&lt;=(>))assigned(?!\&lt;)(?!>)/gi</p>

<p>which matches if assigned or Assigned is the start of text in a tag, but not on the others. It does a good job of ignoring the attributes and tags but it is not working well if the text does not start with the search string.</p>

<p>Can anyone help me out here? I've been working on this for a an hour now but can' find a solution (RegExp noob here..)</p>

<h1>UPDATE 2</h1>

<p><a href="https://regex101.com/r/ZwXr4Y/1" rel="nofollow">https://regex101.com/r/ZwXr4Y/1</a> show the remaining problem regarding HTML entities and HTML comments.</p>

<p>When searching the problem left is that <code>&amp;nbsp;</code> is not ignored, all text inside HTML entities and comments should be ignored. So when searching for "b" it should not match <code>&amp;nbsp;</code> even if the HTML entity is correctly between HTML tags.</p>