Find and replace several words without affecting future replacements
<p>What I want to do is some kind of "banned words" highlighting.</p>

<p>Here are the values I have :</p>

<p>I have a list of bannedwords in an array</p>

<pre><code>{ "word1", "word2", "word3", "word4" }
</code></pre>

<p>I have a string representing a comment</p>

<pre><code>"i want to word1ban this word3 stupidword4 comment"
</code></pre>

<p>I want to highlight these within html bold tags (<code>&lt;b&gt; &lt;/b&gt;</code>).
So for example, this comment string would become :</p>

<pre><code>"i want to &lt;b&gt;word1&lt;/b&gt;ban this &lt;b&gt;word3&lt;/b&gt; stupid&lt;b&gt;word4&lt;/b&gt; comment"
</code></pre>

<p>The way I do this actually, is using a regex replacement and it works pretty well except for one thing which is annoying for me.</p>

<pre><code>foreach (var word in words)
{
    value = Regex.Replace(value, string.Format(@"{0}", Regex.Escape(HttpUtility.HtmlEncode(word))), "&lt;b&gt;" + word + "&lt;/b&gt;", RegexOptions.IgnoreCase);
}
</code></pre>

<p>The problem with this, and it also depends of the order of the words in the array, is if one of the banned words will affect your replacement (<code>&lt;b&gt;</code> or <code>&lt;/b&gt;</code>)</p>

<p>For example, if you add this to the banned words : <code>&lt;b</code></p>

<p>Following the code, the first iteration result will be :</p>

<pre><code>"i want to &lt;b&gt;word1&lt;/b&gt;ban this &lt;b&gt;word3&lt;/b&gt; stupid&lt;b&gt;word4&lt;/b&gt; comment"
</code></pre>

<p>Then replacing with <code>&lt;b</code> after it will be :</p>

<pre><code>"i want to &lt;b&gt;&lt;b&lt;/b&gt;&gt;word1&lt;/b&gt;ban this &lt;b&gt;&lt;b&lt;/b&gt;&gt;word3&lt;/b&gt; stupid&lt;b&gt;&lt;b&lt;/b&gt;&gt;word4&lt;/b&gt; comment"
</code></pre>

<p>I don't want to affect my replacement. I'm wondering how we can do this. I tried adding exceptions to my regex to exclude <code>&lt;b&gt;</code> and <code>&lt;/b&gt;</code> in the replacement without success.</p>
