如何提取以下文本中的超链接,求C#代码
正则表达式
<html><head><meta http-equiv=Content-Type content="text/html;charset=gb2312"><title>百度一下,你就知道      </title><style>body{margin:4px 0}p{margin:0;padding:0}img{border:0}td,p,#u{font-size:12px}#b,#u,#l td,a{font-family:arial}#kw{font:16px Verdana;height:1.78em;padding-top:2px}#b{height:30px;padding-top:4px}#b,#b a{color:#77c}#u{padding-right:10px;line-height:19px;text-align:right;margin:0 0 3px !important;margin:0 0 10px}#sb{height:2em;width:5.6em}#km{height:50px}#l{margin:0 0 5px 15px}#l td{padding-left:107px}p,table{width:650px;border:0}#l td,#sb,#km{font-size:14px}#l a,#l b{margin-right:1.14em}a{color:#00c}a:active{color:#f60}#hp{position:absolute;margin-left:6px}#lg{margin:-26px 0 -44px}#lk{width:auto;line-height:18px;vertical-align:top}#sug{border:1px solid #817F82;display:none;position:absolute;top:28px;left:0;-moz-user-select:none}#sug td{font:14px verdana}.mo{background-color:#36c;color:#fff}.ml{background-color:#fff;color:#000}</style></head>
<body><div id“WindowsApplication2.vshost.exe”(托管): 已加载“C:\WINDOWS\assembly\GAC_MSIL\mscorlib.resources\2.0.0.0_zh-CHS_b77a5c561934e089\mscorlib.resources.dll”,未加载符号。
=u><a href=http://passport.baidu.com/?login&tpl=mn>登录</a></div><center><img src=http://www.baidu.com/img/baidu_logo.gif width=270 height=129 usemap="#mp" id=lg><br><br><br><br><table cellpadding=0 cellspacing=0 id=l><tr><td><div id=m><a onclick=s(this) href=http://news.baidu.com>新&nbsp;闻</a><b>网&nbsp;页</b><a onclick=s(this) href=http://tieba.baidu.com>贴&nbsp;吧</a><a onclick=s(this) href=http://zhidao.baidu.com>知&nbsp;道</a><a onclick=s(this) href=http://mp3.baidu.com>MP3</a><a onclick=s(this) href=http://image.baidu.com>图&nbsp;片</a><a onclick=s(this) href=http://video.baidu.com>视&nbsp;频</a></div></td></tr></table>
<table cellpadding=0 cellspacing=0 style="margin-left:15px"><tr valign=top><td style="height:62px;padding-left:92px" nowrap><div style="position:relative"><form name=f action=/s><span id=in><input type=text name=wd id=kw size=42 maxlength=100></span> <input type=submit value=百度一下 id=sb><div id=sug onselectstart="return false"></div><span id=hp><a href=/search/jiqiao.html>帮助</a><br><a href=/gaoji/advanced.html>高级</a></span></form></div></td></tr></table>
<p id=km><a href=http://hi.baidu.com>空间</a>&nbsp;&nbsp;<a href=http://www.hao123.com>hao123</a>&nbsp;|&nbsp;<a href=/more/ style="font-family:宋体">更多>></a></p>
<p style=height:60px><table cellpadding=0 cellspacing=0 id=lk><tr><td></td></tr></table></p>
<p style=height:30px><a onClick="this.style.behavior='url(#default#homepage)';this.setHomePage('http://www.baidu.com')" href=http://utility.baidu.com/traf/click.php?id=215&url=http://www.baidu.com>把百度设为主页</a></p><p style=height:14px><a href=http://jingjia.baidu.com>企业推广</a> | <a href=http://top.baidu.com>搜索风云榜</a> | <a href=/home.html>关于百度</a> | <a href=http://ir.baidu.com>About Baidu</a></p><p id=b>&copy;2008 Baidu <a href=http://www.baidu.com/duty/>使用百度前必读</a> <a href=http://www.miibeian.gov.cn target=_blank>京ICP证030173号</a> <img src=http://gimg.baidu.com/img/gs.gif></p><map name=mp><area shape=rect coords="43,22,227,91" href=http://hi.baidu.com/baidu/ target=_blank title="点此进入 百度空间"></map></center></body>
<script>var w=document.f.wd;function s(o){if(w.value.length>0){var h=o.href;var q=encodeURIComponent(w.value);if(h.indexOf("q=")!=-1){o.href=h.replace(new RegExp("q=[^&$]*"),"q="+q)}else{o.href+="?q="+q}}};(function(){if(new RegExp("q=([^&]+)").test(location.search)){w.value=decodeURIComponent(RegExp.$1)}})();if(navigator.cookieEnabled && /BAIDUID=\w{30}(\w{2})([^;]*)(;|$)/.test(document.cookie) && !/:SU=0/.test(RegExp.$2)){var num = parseInt(RegExp.$1, 16);if(num<12){var i = document.createElement('INPUT');i.name='tn';i.value='baidutnta'+(num<6?'1':'0');i.type='hidden';document.f.appendChild(i);if(num<6){var s=document.createElement('SCRIPT');s.src='http://www.baidu.com/js/bdsug.js?v=1.0.0.8';document.getElementsByTagName('HEAD')[0].appendChild(s);document.getElementById('in').innerHTML='<input type=text name=wd id=kw size=42 maxlength=100 autocomplete=off>';}}}window.onunload=function(){};document.f.wd.focus();</script></html><!--83ae802d8e087130-->

解决方案 »

  1.   

    http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
      

  2.   


    string str="(?<=\\<\s*[aA]\s+href[=])\S*"
      

  3.   


    string str="(?<=\\<\s*[aA]\s+href[=])(\S|[^>])*"
      

  4.   

    一般超链接都是<a href=后面可能会有单引或双引号,也可能没有,像百度的超链接就没有引号,正则可以这样写
    string pattern=@"<a href=(?<link>[^\s>]+)";
    Regex reg=new Regex(pattern);
    string result=string.Empty;
    foreach(Match m in reg.Matches("文本内容"))
    {
     result+=m.Groups["link"].Value+"\r\n";
    }
      

  5.   

    我在写一个<a\b(?:"[^"]*"|'[^']*'|[^"'>])+?href=(['"]?)([^\s>"']*(?:(?!\1).[^\s>"']*)*)\1(?:"[^"]*"|'[^']*'|[^"'>])*>
      

  6.   

    我写的这个 要用一个委托来 保存 结果 
    $1,$2 都有可能出现结果 
    LZ 自己实现 其他的吧上面写的那个正则 是根据 ' ," ,和没有引号的情况去匹配的 基本可以杜绝所有混淆的url
      

  7.   

    也用于 <a href=' ' tile='href="123.html"'
    混淆的写法
    lz 可以尝试一下啊
      

  8.   

    <a\b(?:"[^"]*"|'[^']*'|[^"'>])+?href=(['"]?)([^\s>"']*(?:(?!\1).[^\s>"']*)*)\1(?:"[^"]*"|'[^']*'|[^"'>])*>
    就避免了
    这种情况
    <a href=http://www.miibeian.gov.cn target="href='123'">京ICP证030173号 </a> 
    target 中的混淆url
      

  9.   

    <a\b(?:"[^"]*"|'[^']*'|[^"'>])+?href=(['"]?)([^\s>"']*(?:(?!\1).[^\s>"']*)*)\1(?:"[^"]*"|'[^']*'|[^"'>])*> 
    咋用啊
    @bhtfg538  
    能否提供代码
      

  10.   

    string pattern=@"<a href=(?<link>[^\s>]+)";
    Regex reg=new Regex(pattern);
    string result=string.Empty;
    foreach(Match m in reg.Matches("文本内容"))
    {
     result+=m.Groups["link"].Value+"\r\n";
    }
      

  11.   

    我以前提取用的是indexof + subString 
    嘿嘿