悟生慧

 

正则去掉所有HTML标记

 public static string ClearStr(string yourStr)
    {
        string str = string.Empty;
        str = Regex.Replace(yourStr,"<.+?>"," ", RegexOptions.IgnoreCase);//一个去掉所有HTML标记

        str = Regex.Replace(yourStr, "/<(?!img).*?>/g", " ", RegexOptions.IgnoreCase);//这是保留Img和<br>

        str = Regex.Replace(yourStr,"<(?!/?br|/?img)[^<>]*>","",RegexOptions.IgnoreCase);//保留Img和<Br>
        return str;
    }

posted on 2010-07-16 11:12  悟生慧  阅读(238)  评论(0编辑  收藏  举报

导航