如何从ASP.NET中的HTML编辑器内容中删除div标签
问题描述:
我正在处理一个应用程序.在这个应用程序中,我必须将News详细信息插入Sql Databse中.为了输入Article,我使用了HTML编辑器.我的代码是:-
I am working on an application. In this application I have to insert News detail into Sql Databse.For entering Article i have used a Html editor.My code is:-
objNews.Article = Server.HtmlEncode(Regex.Replace(ckedi.Content.Trim().ToString(), "</?(div|DIV).*?>", ""));
我已经使用regex.Replace从html编辑器中的字符串中删除标签.当我在html编辑器中输入div标签时,它会删除div标签,但也会同时删除其他标签.例如:如果我输入Text as:
I have used regex.Replace to remove tag from the string in html editor.When i enter div tag into the html editor then it removes div tag but it also remove other tag also.as ex: If i enter Text as:
<p><div width="200px;"> Sachin Retires from Cricket.</div></p>
然后将文本存储为
p> Sachin Retires from Cricket./p>
此正则表达式也删除了p标签.我只想删除div标签而不是p标签.请帮助我.
This regex removes p tag also.I want to remove div tag only not p tag.Please help me.
答
尝试以下方法:
(?i)</?div[^>]*>
说明