去掉字符串不需要的HTML标记(正则表达式)

具体实现如下: 

     //除掉HTML保留格式外的其他格式
     string[] HoldTags = { "strong", "em", "u", "strike", "sub", "sup", "img", "b", "i", "div", "p", "center" };//保留的关键字
     string RegStr = string.Format(@"<(?!((/?\s?{0})))[^>]+>", string.Join(@"\b)|(/?\s?", HoldTags));
     System.Text.RegularExpressions.Regex Reg = new System.Text.RegularExpressions.Regex(RegStr, System.Text.RegularExpressions.RegexOptions.Compiled |    System.Text.RegularExpressions.RegexOptions.Multiline | System.Text.RegularExpressions.RegexOptions.IgnoreCase);
     string  QuestionAllContent="<strong>中国</strong>真的好强大<tes>!</tes>";//要进行去掉的字符串

     QuestionAllContent = Reg.Replace(QuestionAllContent, "");

     最后QuestionAllContent的内容为:“="<strong>中国</strong>真的好强大!”

原文地址:https://www.cnblogs.com/BeyondWJsel/p/2650500.html