I have a string containing HTML and I need to replace some words to be links - I do this with the following code;
string lNewHTML = Regex.Replace(lOldHTML, "(\bword1\b|\bword2|word3\b)", "<a href=\"page.aspx#$1\">$1</a>", RegexOptions.IgnoreCase);
The code works, but I need to include some exceptions to the replace - e.g. I will not replace anything i an img-, li- and a-tag (including link-text and attributes like href and title) but still allow replacements in p-, td- and div-tags.
Can anyone figure this one out?