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, "");

            }

  • 相关阅读:
    mysql面试知识点
    计算机网络
    BFS
    拓扑排序
    双指针
    回溯算法
    hash表 算法模板和相关题目
    桶排序及其应用
    滑动窗口
    贪心算法
  • 原文地址:https://www.cnblogs.com/suwh/p/2975736.html
Copyright © 2011-2022 走看看