zoukankan      html  css  js  c++  java
  • C# 正则表达式 去除HTML标签 C#后台

      private static string RemoveSpecifyHtml(string ctx)
            {

                string[] holdTags = { "a", "img" };//保留的 tag  

                // <(?!((/?\s?li\b)|(/?\s?ul\b)|(/?\s?a\b)|(/?\s?img\b)|(/?\s?br\b)|(/?\s?span\b)|(/?\s?b\b)))[^>]+>  

                string regStr = string.Format(@"<(?!((/?\s?{0})))[^>]+>", string.Join(@"\b)|(/?\s?", holdTags));

                Regex reg = new Regex(regStr, RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.IgnoreCase);
                string str = reg.Replace(ctx, "");
                Regex regex = new Regex("&.+?;", RegexOptions.IgnoreCase);

                return regex.Replace(str, "");

            }

  • 相关阅读:
    Sword 17
    Sword 16
    Sword 15
    Sword 14-II
    Sword 14-I
    Sword 13
    Sword 11
    Sword 10-II
    Sword 10
    【python+selenium】三种等待方式
  • 原文地址:https://www.cnblogs.com/suwh/p/2975736.html
Copyright © 2011-2022 走看看