@"<a[^>]*?href=([""']?)(?<url>[^""'\s>]*)\1[^>]*>"
匹配超链接。这个是你之前给我的。。但现在有遇到几种情况,一个就是连接是单引号的。如<a href ='newsdetails.aspx?news_id=81804' class="general">就没办法抓下来了,还有就是换行和空格。
没办法,再次求助于你。。

解决方案 »

  1.   

    这个不是因为单引号的问题,而是在href后面有空格,加下判断就好了Regex reg = new Regex(@"(?i)<a[^>]*?href\s*=\s*([""']?)(?<url>[^""'\s>]*)\1[^>]*>");
    MatchCollection mc = reg.Matches(yourStr);
    foreach (Match m in mc)
    {
        richTextBox2.Text += m.Groups["url"].Value + "\n";
    }如果还有不满足的,比如你说的换行和空格,给出实例
      

  2.   

    <tr>
    <td width="1%">&nbsp;</td>
    <td colspan="2">
    <a href ='newsdetails.aspx?news_id=81804' class="general">
    <font color="#1C4E8D" face="arial" style="font-size:15px"><b> Retail chain Buslik is expanding across the country
    </b></font></a>
    <br>
    <font color="#1C4E8D" face="arial" style="font-size:11px">
    January&nbsp;30,&nbsp;2010
    </font>&nbsp;<font font color="#1C4E8D" face="arial" style="font-size:11px">(Belarus)</font>
    </td>
    <td width="1%">&nbsp;</td> </tr>
    主要是一些外国的网站。谢谢啊。我先试试。
      

  3.   

    这是vs自带的url验证正则
    http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?这是DZNT的方法
            readonly static Regex RgValidURL = new Regex(@"^(http|https)\://([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&%\$\-]+)*@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|localhost|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{1,10}))(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\?\'\\\+&%\$#\=~_\-]+))*$", RegexOptions.Compiled);
      

  4.   

    这是vs自带的url验证正则
    http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?这是DZNT的方法
            readonly static Regex RgValidURL = new Regex(@"^(http|https)\://([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&%\$\-]+)*@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|localhost|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{1,10}))(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\?\'\\\+&%\$#\=~_\-]+))*$", RegexOptions.Compiled); 两个都是对的