C#匹配HTML标签,正则表达式谁会?
答案:2 悬赏:50
解决时间 2021-02-20 02:02
- 提问者网友:一抹荒凉废墟
- 2021-02-19 22:09
C#匹配HTML标签,正则表达式谁会?
最佳答案
- 二级知识专家网友:底特律间谍
- 2021-02-19 22:40
JS:
function StripHtml(html)
{
var scriptregex = ".]*>[sS]*?";
var scripts = new RegExp(scriptregex, "gim");
html = html.replace(scripts, " ");
//Stripts the ";
var styles = new RegExp(styleregex , "gim");
html = html.replace(styles, " ");
//Strips the HTML tags from the html
var objRegExp = new RegExp("<(.| )+?>", "gim");
varstrOutput = html.replace(objRegExp, " ");
//Replace all < and > with < and >
strOutput = strOutput.replace(/, "<");
strOutput = strOutput.replace(/>/, ">");
objRegExp = null;
return strOutput;
}
.NET:
过滤不安全的HTML代码
[AjaxPro.AjaxMethod()]
public String UnSafeHTMLFilter(string html)
{
Regex regex1 = new Regex(@"标记
html = regex2.Replace(html, ""); //过滤href=javascript: () 属性
html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on...事件
html = regex4.Replace(html, ""); //过滤iframe
html = regex5.Replace(html, ""); //过滤frameset
return html;
}
function StripHtml(html)
{
var scriptregex = "
var scripts = new RegExp(scriptregex, "gim");
html = html.replace(scripts, " ");
//Stripts the ";
var styles = new RegExp(styleregex , "gim");
html = html.replace(styles, " ");
//Strips the HTML tags from the html
var objRegExp = new RegExp("<(.| )+?>", "gim");
varstrOutput = html.replace(objRegExp, " ");
//Replace all < and > with < and >
strOutput = strOutput.replace(/, "<");
strOutput = strOutput.replace(/>/, ">");
objRegExp = null;
return strOutput;
}
.NET:
过滤不安全的HTML代码
[AjaxPro.AjaxMethod()]
public String UnSafeHTMLFilter(string html)
{
Regex regex1 = new Regex(@"标记
html = regex2.Replace(html, ""); //过滤href=javascript: () 属性
html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on...事件
html = regex4.Replace(html, ""); //过滤iframe
html = regex5.Replace(html, ""); //过滤frameset
return html;
}
全部回答
- 1楼网友:轻雾山林
- 2021-02-19 22:57
"^\<[\S]+\>([\S]*)\<\/[\S]+\>"
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯