Reputation: 97
I have code like this
string pattern = "<(.|\n)+?>";
System.Text.RegularExpressions.Regex regEx = new System.Text.RegularExpressions.Reg(pattern);
string result = "";
result = regEx.Replace(htmlText, "");
In this "htmlText" will have some html code which also contains break tags. Right now its replacing all the html tags, but I want to leave break tag and replace the rest. How can i do it? Anybody have any idea?
Thanks
Upvotes: 3
Views: 3022
Reputation: 47144
This should work:
string html = "<span>test<br><br /></span>";
Regex regex = new Regex("<[^(?!br)>]*>", RegexOptions.Compiled);
string result = regex.Replace(html, string.Empty);
Upvotes: 0