C#分析网站的网页的文章时,只想要文章的文字,不要里面的超级链接,如何去掉
比如:中国<a href="http://www.cctv.com">中央电视台</a>新闻我只要:中国中央电视台新闻,不要里面的<a ....>和</a>

解决方案 »

  1.   

    直接Remove掉 正则表达式<(\w*)(.*?)> </\1>
      

  2.   

    <(\w*)(.*?)> </\1>  就是相当等于 你 的<a href="http://www.cctv.com"></a>
      

  3.   

    貌似刚回答了一个一样的,也是你发的么?Match m = Regex.Match(@"中国<a href="http://www.cctv.com">中央电视台</a>新闻",@"(?<=<a[^>]+>).*?(?=</a>)");
    MessageBox.Show(m.Value);//就是你要的
      

  4.   


    private static void TestRegex03()
    {
        Match m = Regex.Match(@"中国<a href=""http://www.cctv.com"">中央电视台</a>新闻", @"(?<=<a[^>]+>).*?(?=</a>)");
        MessageBox.Show(m.Value);//就是你要的
    }
      

  5.   


            string s = "中国<a href=\"http://www.cctv.com\">中央电视台</a>新闻";
            s = System.Text.RegularExpressions.Regex.Replace(s, @"(<a\s{0,}[^>]*?href=['""]?[^'""].*?['""]?\s{0,}[^>]*?>)([^<>]*?)(</a>)", "$2");
            Response.Write(s);