原文:<a href="http://www.wywan.com" >aaa1</a><a href="http://www.dnfclub.com" >aaa2</a><a href="http://www.97bet.com" >aaaa3</a><a href="http://www.hao123.com" >hao123</a>
要求提取除了www.dnfclub.com 之外的所有超链接 格式为www.97bet.com

解决方案 »

  1.   

    已经写了一点点 <a\s+\S*href=\W*http:// 到了哪个不提取那里卡主了
    帮下忙啊 谢谢了
      

  2.   

    <a[^>]+?href=['"]http://www\.(?!=dnfclub)[^>]+?>
      

  3.   

    写个完整点的string input=@"<a href="http://www.wywan.com" >aaa1</a><a href="http://www.dnfclub.com" >aaa2</a><a href="http://www.97bet.com" >aaaa3</a><a href="http://www.hao123.com" >hao123</a>";
    MatchCollection mc=Regex.Matches(input,@"(?is)<a\s*href=""https?://www.[^dnfclub]+.[^""]+""[^>]*>.*?</a>");
    froeach(Match m in mc)
    {
       Console.WriteLine(m.Value);
    }
      

  4.   


    改一下string input=@"<a href=""http://www.wywan.com"" >aaa1</a><a href=""http://www.dnfclub.com"" >aaa2</a><a href=""http://www.97bet.com"" >aaaa3</a><a href=""http://www.hao123.com"" >hao123</a>";
    MatchCollection mc=Regex.Matches(input,@"(?is)<a\s*href=""https?://www.[^dnfclub]+.[^""]+""[^>]*>.*?</a>");
    froeach(Match m in mc)
    {
       Console.WriteLine(m.Value);
    }
      

  5.   

    https?://www.[^dnfclub]+
    [^dnfclub]这个是排除型字符组不是单词
      

  6.   

      public int ljcount()
              {
                  string bdurl = "http://" + url;
                  string bdcontent =@getHtml(bdurl, "");
                 MatchCollection mc=Regex.Matches(bdcontent,@"(?is)<a\s*href=""https?://www.[^97bet]+.[^""]+""[^>]*>.*?</a>");             foreach (Match m in mc)
                 {
                     MessageBox.Show(m.Value);
                 }             return mc.Count;
              }不知道为什么 提取不出啦  C#新手 帮忙看下
      

  7.   

    再改改,你看看bdcontent是正确的嘛?string input = @"<a href=""http://www.wywan.com"" >aaa1</a><a href=""http://www.dnfclub.com"" >aaa2</a><a href=""http://www.97bet.com"" >aaaa3</a><a href=""http://www.hao123.com"" >hao123</a><a href=""http://www.dnfclu.com"" >aaa4</a>";
                MatchCollection mcReg = Regex.Matches(input, @"(?is)<a\s*href=""https?://www.(?!(dnfclub))+.[^""]+""[^>]*>.*?</a>");
                foreach (Match m in mcReg)
                {
                    Console.WriteLine(m.Value);
                }
      

  8.   

    我调试了 bdcontent是有内容的!
    为什么获取不到匹配内容
      

  9.   

    我7楼也是可以正确匹配到你需要的信息,你把你 bdcontent贴出来
      

  10.   

    好像好了 但是还是想麻烦再改下就是我只想提取到网址。
    现在提取到的是包含<a href这些的
      

  11.   


    string input = @"<a href=""http://www.wywan.com"" >aaa1</a><a href=""http://www.dnfclub.com"" >aaa2</a><a href=""http://www.97bet.com"" >aaaa3</a><a href=""http://www.hao123.com"" >hao123</a><a href=""http://www.dnfclu.com"" >aaa4</a>";
                MatchCollection mcReg = Regex.Matches(input, @"(?is)<a\s*href=""(https?://www.(?!(dnfclub))+.[^""]+)""[^>]*>.*?</a>");
                foreach (Match m in mcReg)
                {
                    Console.WriteLine(m.Groups[1].Value);
                }
      

  12.   

    老大 还要帮忙修改下正则 就是<a href=这里 后面有可能是"也可以是'也可以什么都没
    就是说有这3种可能
    <a href="http://..
    <a href='http://
    <a href=http://
      

  13.   

    正则改成如下
     MatchCollection mcReg = Regex.Matches(input, @"(?is)<a\s*href=[""']*(https?://www.(?!(dnfclub))+.[^""']+)[""']*[^>]*>.*?</a>");