今天在做对文章内容过滤时,需要对含有JS的部份进行过滤转换.固参考了一下动网,写了这个函数.希望对有需要的人有所帮助.
public
static
string
FilterJS(
string
str)
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...
{
Regex re = new Regex("$",RegexOptions.IgnoreCase);
str = re.Replace(str,"$");
re = new Regex("$",RegexOptions.IgnoreCase);
str = re.Replace(str,"$");
re = new Regex("'",RegexOptions.IgnoreCase);
str = re.Replace(str,"'");
re = new Regex("'",RegexOptions.IgnoreCase);
str = re.Replace(str,"'");
string jslist = @"(&#([0-9][0-9]*)|function|meta|window.|script|js:|about:|file:|Document.|vbs:|frame|cookie|on(finish|mouse|Exit=|error|click|key|load|focus|Blur))";
re = new Regex("<((.[^>]*" + jslist + "[^>]*)|" + jslist + ")>",RegexOptions.IgnoreCase);
str = re.Replace(str,"<$1>");
return str;
}