I would like to replace words in a html string with another word, but it must only replace the exact word and not if it is part of the spelling of part of a word. The problem that I am having is that the html open or closing tags or other html elements are affecting what words are matched in the regex or it is replacing parts of words.
PostTxt = “<div>The <b>cat</b> sat on the mat, what a catastrophe.
The <span>cat</span> is not allowed on the mat. This makes things complicated; the cat  must go!
</div><p>cat cat cat</p>”;
string pattern = "cat";
//replacement string to use
string replacement = "******";
//Replace words
PostTxt = Regex.Replace(PostTxt, pattern, replacement, RegexOptions.IgnoreCase);
}
I would like it to return.
<div>The <b>***</b> sat on the mat, what a catastrophe. The <span>***</span> is not allowed on the mat. This makes things complicated; the ***  must go! </div><p>*** *** ***</p>
Any suggestions and help will be greatly appreciated.