开发者

Exclude <br> tag from regex not to remove from text?

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 cod开发者_开发知识库e 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


You could try this one:

<(?!br|/br).+?>


This should work:

string html = "<span>test<br><br /></span>";
Regex regex = new Regex("<[^(?!br)>]*>", RegexOptions.Compiled);
string result = regex.Replace(html, string.Empty);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜