Matching a term that contains nested HTML
<p>I have been having trouble finding a solution to this problem.<br/>
I am parsing the content of a number of ebooks, finding specific terms and characters, marking the locations and lengths of each term.<br/></p>

<p>A normal case would be something like this (excerpts from A Game of Thrones):<br/></p>

<blockquote>
  <p>"When he paused to look down, his head swam dizzily and he felt his fingers slipping. Bran cried out and clung for dear life."<br/></p>
</blockquote>

<p>If we are searching for the character "Bran", its location is 85 and length is 4. Easy enough.</p>

<p>My issue arises when there is a paragraph like this:<br/></p>



<pre class="lang-html prettyprint-override"><code>&lt;span height="-0em"&gt;&lt;font size="7"&gt;D&lt;/font&gt;&lt;/span&gt;aenerys Targaryen wed Khal Drogo
</code></pre>

<p>We need to match "Daenerys Targaryn". It is easy enough to strip the HTML and match the string, but in this example the result needs to include the HTML. Thus the expected result would here be would be location = 0, length = 67.</p>

<p>Another situation, caused by random anchor tags scattered throughout:<br/></p>

<pre class="lang-html prettyprint-override"><code>Did anyone outside the Vale even suspect where Catelyn &lt;a&gt;&lt;/a&gt;Stark had taken him?
</code></pre>

<p>Again, searching for "Catelyn Stark" needs to include the HTML, so location = 47, length = 20.</p>

<p>I have been able to get around it temporarily by adding those specific cases (searching for "Catelyn &lt;a&gt;&lt;/a&gt;Stark specifically), but clearly I should have a more robust solution, which I cannot seem to get my head around. My attempts have been using RegEx but with limited success.<br/>
I have found various questions regarding HTML matching/stripping (and whether or not to use RegEx =)), but this case seems to be somewhat unique.<br/>
Stripping the tags isn't an option as the content must be preserved.<br/>
This is within a stand-alone C# application.<br/>
Any ideas, steps in the right direction, or similar examples should your search go better than mine would be greatly appreciated!</p>
