正则去掉所有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;
    }

你可能感兴趣的:(html)