string temp = "<tr class=\"datagrid_item\"><td class=\"datagrid_item_date\" width=\"100\">02/18/09  </td><td class=\"datagrid_item\">Corp. News</td><td class=\"datagrid_item\"><div align=left><a href='newsdetail.aspx?auno=11253&ntype='>Digital Signage Expo 2009 in Las Vegas at the Las Vegas Convention Center (Feb. 24-26). </div></td> </tr><tr class=\"datagrid_item\"><td class=\"datagrid_item_date\" width=\"100\">02/04/09  </td><td class=\"datagrid_item\">Product News</td><td class=\"datagrid_item\"><div align=left><a href='newsdetail.aspx?auno=11250&ntype='>Fanless 2.4L Digital Engine™ (GM45 Chipset) Supports 45nm Core™ 2 Duo</div></td></tr><tr class=\"datagrid_item\"><td class=\"datagrid_item_date\" width=\"100\">02/04/09  </td><td class=\"datagrid_item\">Sales Kit</td><td class=\"datagrid_item\"><div align=left><a href='newsdetail.aspx?auno=11251&ntype='>DEX4501_Sales_Kit</div></td></tr><tr class=\"datagrid_item\"><td class=\"datagrid_item_date\" width=\"100\">01/16/09  </td><td class=\"datagrid_item\">Aopen Mike</td><td class=\"datagrid_item\"><div align=left><a href='newsdetail.aspx?auno=11225&ntype='>AOpen Mike Newsletter - January 2009</div></td></tr>";            MatchCollection mc = Regex.Matches(temp, @"(<a href='newsdetail.aspx?auno=)([\d\D]+)('>)", RegexOptions.IgnoreCase);
            for (int i = 0; i < mc.Count; i++)
            {
               TextBox1.Text+= mc[i].Value + "\n";
            }我只要提取出<a href='newsdetail.aspx?auno=********'>)类似这样的东西(超链接),为什么我的正则表达式一个都匹配不到呢?
大家帮个忙啊

解决方案 »

  1.   

    ?要转义,+后面加?防止贪婪匹配
    在你基础上改一下就是
    @"(<a href='newsdetail.aspx\?auno=)([\d\D]+?)('>)"
      

  2.   

    <a href='newsdetail.aspx\?auno\=.*?>
      

  3.   


      string temp = "<tr class=\"datagrid_item\"><td class=\"datagrid_item_date\" width=\"100\">02/18/09  </td><td class=\"datagrid_item\">Corp. News</td><td class=\"datagrid_item\"><div align=left><a href='newsdetail.aspx?auno=11253&ntype='>Digital Signage Expo 2009 in Las Vegas at the Las Vegas Convention Center (Feb. 24-26). </div></td>    </tr><tr class=\"datagrid_item\"><td class=\"datagrid_item_date\" width=\"100\">02/04/09  </td><td class=\"datagrid_item\">Product News</td><td class=\"datagrid_item\"><div align=left><a href='newsdetail.aspx?auno=11250&ntype='>Fanless 2.4L Digital Engine™ (GM45 Chipset) Supports 45nm Core™ 2 Duo</div></td></tr><tr class=\"datagrid_item\"><td class=\"datagrid_item_date\" width=\"100\">02/04/09  </td><td class=\"datagrid_item\">Sales Kit</td><td class=\"datagrid_item\"><div align=left><a href='newsdetail.aspx?auno=11251&ntype='>DEX4501_Sales_Kit</div></td></tr><tr class=\"datagrid_item\"><td class=\"datagrid_item_date\" width=\"100\">01/16/09  </td><td class=\"datagrid_item\">Aopen Mike</td><td class=\"datagrid_item\"><div align=left><a href='newsdetail.aspx?auno=11225&ntype='>AOpen Mike Newsletter - January 2009</div></td></tr>";            MatchCollection mc = Regex.Matches(temp, @"<a\s+href='[^']+'>", RegexOptions.IgnoreCase);
                for (int i = 0; i < mc.Count; i++)
                {
                   TextBox1.Text+= mc[i].Value + "\n";
                }/*结果:
    <a href='newsdetail.aspx?auno=11253&ntype='>
    <a href='newsdetail.aspx?auno=11250&ntype='>
    <a href='newsdetail.aspx?auno=11251&ntype='>
    <a href='newsdetail.aspx?auno=11225&ntype='>
    */
      

  4.   

    CutBug 和 2sanshi 的方法都不错。谢谢了。。wackyboy 的方法会把所有超链接都捞出来。。因为我的页面中还有 <a href='defaul.aspx'>其他链接 。。谢谢大家。。