title: Regex - Replace text in HTML string when not contained within HTML tags
body: <p>I'm hoping someone can help with this little problem.</p>
  
  <p>I've have a HTML string, a simplified example of which is shown below, which I need to find and replace text within. But only if that text doesn't appear within HTML tags i.e. "&lt;" and ">".</p>
  
  <pre><code>&lt;table width="100%" border="0" cellspacing="0" cellpadding="0"&gt;
  &lt;tr&gt;
  &lt;td&gt;
  In this text I'd like to replace the word "in" with another piece of text instead.
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>For example I'd like to replace the word "in" with the span string below resulting in the full HTML below that.</p>
  
  <pre><code>&lt;span class="highlight"&gt;in&lt;/span&gt;
  
  
  &lt;table width="100%" border="0" cellspacing="0" cellpadding="0"&gt;
  &lt;tr&gt;
  &lt;td&gt;
  &lt;span class="highlight"&gt;In&lt;/span&gt; this text I'd like to replace the word "&lt;span class="highlight"&gt;in&lt;/span&gt;" with another piece of text &lt;span class="highlight"&gt;in&lt;/span&gt;stead.
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>The reason I only want the text replacing which appears between ">" and "&lt;" is becasue I don't want the HTML to break by replacing the word "in" in the "cellspacing" and "cellpadding" attributes.</p>
  
  <p>If this can't be solved using regex I'm also open to doing it in VB.NET, Javascript or JQuery.</p>
  
  <p>Thanks in advance for any help you can offer!</p>
  
  <p>SOLVED!</p>
  
  <p>Thanks to MiddleCSharp for your wisdom</p>
  
  <pre><code>Dim rgx As New Regex(String.Format("\b{0}\b", SearchText, RegexOptions.IgnoreCase) 
  ltrPageCopy.Text = rgx.Replace(HTMLText, String.Format("&lt;span class=""highlight""&gt;{0}&lt;/span&gt;", SearchText))
  </code></pre>