I have a string containing HTML and I need to replace some words to be links (I know, working with regex against HTML is not accepted by all developers, but I cannot see an easy solution with any other technique) - 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.
By using the following code I can avoid replacing in attributes;
But with the above code it still replaces words in e.g. links and headlines which is a no-go.
The last example I have seems to do what I need - but if my HTML-string contains more than a few characters my application crashes;
Can anyone figure out a solution to this?
View Complete Post