C# 正则过滤html,js,css代码

来源:互联网 发布:卖家数据分析 编辑:程序博客网 时间:2024/05/17 02:38
    public static string InputText(string text)//过滤html,js,css代码
    {
        text = text.Trim();
        if (string.IsNullOrEmpty(text))
            return string.Empty;
        text = Regex.Replace(text, "[//s]{2,}", " "); //两个或多个空格替换为一个
        text = Regex.Replace(text, "(<[b|B][r|R]/*>)+|(<[p|P](.|//n)*?>)", "/n"); //<br>
        text = Regex.Replace(text, "(//s*&[n|N][b|B][s|S][p|P];//s*)+", " "); //&nbsp;
        text = Regex.Replace(text, "<(.|//n)*?>", string.Empty); //其它任何标记
        text = text.Replace("'", "''");
        return text;
    } 
原创粉丝点击