C#匹配HTML标签,正则表达式谁会?

很简单,就是想要一下一对标签之间的内容比如:<dl>想要的内容</dl>,<a>想要的内容</a>。。。谁能帮小弟一下,谢谢啦... 很简单,就是想要一下一对标签之间的内容

比如:<dl>想要的内容</dl> ,<a>想要的内容</a> 。。。

谁能帮小弟一下,谢谢啦
展开
 我来答
百度网友caef6e2bb
2008-03-08 · TA获得超过2425个赞
知道小有建树答主
回答量:1174
采纳率:0%
帮助的人:1381万
展开全部
JS:
function StripHtml(html)
{
var scriptregex = "<scr" + "ipt[^>.]*>[sS]*?</sc" + "ript>";
var scripts = new RegExp(scriptregex, "gim");
html = html.replace(scripts, " ");

//Stripts the <style> tags from the html
var styleregex = "<style[^>.]*>[sS]*?</style>";
var styles = new RegExp(styleregex , "gim");
html = html.replace(styles, " ");

//Strips the HTML tags from the html
var objRegExp = new RegExp("<(.| )+?>", "gim");
var strOutput = html.replace(objRegExp, " ");

//Replace all < and > with < and >
strOutput = strOutput.replace(/</, "<");
strOutput = strOutput.replace(/>/, ">");

objRegExp = null;
return strOutput;
}

.NET:
<summary>
过滤不安全的HTML代码
</summary>
<param name="html"></param>
<returns></returns>
[AjaxPro.AjaxMethod()]
public String UnSafeHTMLFilter(string html)
{
Regex regex1 = new Regex(@"<script[\s\s]+</script *>", RegexOptions.IgnoreCase);
Regex regex2 = new Regex(@" href *= *[\s\s]*script *:", RegexOptions.IgnoreCase);
Regex regex3 = new Regex(@" on[\s\s]*=", RegexOptions.IgnoreCase);
Regex regex4 = new Regex(@"<iframe[\s\s]+</iframe *>", RegexOptions.IgnoreCase);
Regex regex5 = new Regex(@"<frameset[\s\s]+</frameset *>", RegexOptions.IgnoreCase);
html = regex1.Replace(html, ""); //过滤<script></script>标记
html = regex2.Replace(html, ""); //过滤href=javascript: (<a>) 属性
html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on...事件
html = regex4.Replace(html, ""); //过滤iframe
html = regex5.Replace(html, ""); //过滤frameset
return html;
}
ou6754
2008-03-08 · 超过26用户采纳过TA的回答
知道答主
回答量:53
采纳率:0%
帮助的人:40.7万
展开全部
"^\<[\S]+\>([\S]*)\<\/[\S]+\>"
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式