<style type="text/css"> 
* {margin: 0;padding: 0;}
body{background-color:transparent;}
body {font: 90%/normal Arial, Helvetica, sans-serif;}
a:link {color: #00c;text-decoration: underline;}
a:visited {color: #800080;}
strong {color: #c03;font-weight: normal;}
 
</style> 
主要是想要过滤掉这些代码,但是不知道怎么匹配,求助试过HTML的过滤代码,但是 中间的字母字符过滤不了,

解决方案 »

  1.   

    (?is)<style[^>]*>.*?</style>
      

  2.   

    接楼上
    string result = Regex.Replace(html,@"(?is)<style[^>]*>.*?</style>","");
      

  3.   

    还是正确,不知道哪个的问题
            public static string RemoveStyle(string HtmlCode)
            {
                string MatchVale = HtmlCode;
                foreach (Match s in Regex.Matches(HtmlCode, "<style[^>]*>.*?</style>"))
                {
                    MatchVale = MatchVale.Replace(s.Value, "");
                }            foreach (Match s in Regex.Matches(HtmlCode, "</style>"))
                {
                    MatchVale = MatchVale.Replace(s.Value, "");
                }            return MatchVale;
            }
      

  4.   


      public static string RemoveStyle(string HtmlCode)
            {
                string MatchVale = HtmlCode;
                foreach (Match s in Regex.Matches(HtmlCode, "<style[^>]*>.*?</style>"))
                {
                    MatchVale = MatchVale.Replace(s.Value, "");
                }            foreach (Match s in Regex.Matches(HtmlCode, "</style>"))
                {
                    MatchVale = MatchVale.Replace(s.Value, "");
                }            return MatchVale;
            }
    是这样使用吗??
      

  5.   

     string str = "<style type=\"text/css\">   * {margin: 0;padding: 0;}body{background-color:transparent;}body {font: 90%/normal Arial, Helvetica, sans-serif;}a:link {color: #00c;text-decoration: underline;}a:visited {color: #800080;}strong {color: #c03;font-weight: normal;}</style>";
    Console.Write(Regex.Replace(str, @"(?is)<style[^>]*>(.*?)</style>", ""));