<ul class="mct">
<li>
<a href="../index/vod.htm?qvod%3A%2F%2F681493015%7CF7F2EF8FB2EE49E3E140BA28D7301E17494E16FE%7CFull.Throttle.1995.BDRip.AC3.CN.x264.rmvb%7C?4515" target="_blank">[1]</a>
<li>
<a href="../index/vod.htm?qvod%3A%2F%2F681560833%7CC047C871E39C06FD30B3F3A3F9D392F17A9082DC%7CFull.Throttle.1995.BDRip.AC3.HK.x264.rmvb%7C?4515" target="_blank">[2]</a>
</ul>
如何用正则取出href里的内容?
Regex reg_file = new Regex(@"<a href=""(.*?)"" target=""_blank"">[(.*?)]</a>");
我这样写有问题吗?

解决方案 »

  1.   

    <a[^>]*?href=(['""])?(?<href>[^'""]+)\1[^>]*>取Group["href"].value
      

  2.   

    Regex reg_file = new Regex(@"<a href=""(.*?)"" target=""_blank"">\[(.*?)\]</a>");
    貌似转义一下就可以了
      

  3.   


    void Main()
    {
       string html=@"<ul class=""mct"">
    <li>
    <a href=""../index/vod.htm?qvod%3A%2F%2F681493015%7CF7F2EF8FB2EE49E3E140BA28D7301E17494E16FE%7CFull.Throttle.1995.BDRip.AC3.CN.x264.rmvb%7C?4515"" target=""_blank"">[1]</a>
    <li>
    <a href=""../index/vod.htm?qvod%3A%2F%2F681560833%7CC047C871E39C06FD30B3F3A3F9D392F17A9082DC%7CFull.Throttle.1995.BDRip.AC3.HK.x264.rmvb%7C?4515"" target=""_blank"">[2]</a>
    </ul>";
    foreach(Match m in  Regex.Matches(html,@"<a[^>]*?href=(['""])?(?<href>[^'""]+)\1[^>]*>"))
    {
      Console.WriteLine(m.Groups["href"].Value);
    }
    }/*
    ../index/vod.htm?qvod%3A%2F%2F681493015%7CF7F2EF8FB2EE49E3E140BA28D7301E17494E16FE%7CFull.Throttle.1995.BDRip.AC3.CN.x264.rmvb%7C?4515
    ../index/vod.htm?qvod%3A%2F%2F681560833%7CC047C871E39C06FD30B3F3A3F9D392F17A9082DC%7CFull.Throttle.1995.BDRip.AC3.HK.x264.rmvb%7C?4515
    */
      

  4.   

    不能直接href=""(.*?)""因为网站里有很多href。必须要把<a href="../index/vod.htm?这个当成一对
      

  5.   

    <div id="main">
        <div class="l side">
          <div id="tools">
            <h3>::实用工具::</h3>
            <ul>
              <li><a href="http://tool.115.com/live/speed" target="_blank">上网测速</a></li>
              <li><a href="http://tool.115.com/shouji/" target="_blank">手机查询</a></li>
              <li><a href="http://tool.115.com/live/huoche/" target="_blank">火车时刻</a></li>
              <li><a href="http://tool.115.com/ip/" target="_blank">I P 地址</a></li>
              <li><a href="http://aq.115.com" target="_blank">免费杀毒</a></li>
              <li><a href="http://tool.115.com/live/express/" target="_blank">快递查询</a></li>
              <li><a href="http://tool.115.com/tianqi/" target="_blank">天气预报</a></li>
              <li><a href="http://tool.115.com/live/fanyi/" target="_blank">在线翻译</a></li>
              <li><a href="http://tool.115.com/live/ditu/" target="_blank">城市地图</a></li>
              <li><a href="http://tool.115.com/youbian/" target="_blank">邮编区号</a></li>
            </ul>
          </div>
            <div id="msrc">
            <h3>::影片搜索::</h3>
            <form name="form" action="/files/search.php" method="post" target="_blank">
              选择类型 <span class="select">
              <select name="typeid">
                <option value="title">电影名称</option>
                <option value="actor">演员名称</option>
              </select>
              </span>
              <div id="search">
    关键字 <input type="text" name="keyword" class="k" />
              <input type="submit" value="影片搜索" onClick="if (form.keyword.value.length==0) {alert('请输入关键字!');return false;}" class="btn" /></div>
              <div id="search_auto"></div>
            </form>
          </div>
    <!--
          <div class="slist" id="new">
            <h3>::最近更新::</h3>
            <ul>
            <script src="../js/news.js"></script>
            </ul>
          </div>
    -->
          <div class="slist" id="order">      </div>
          <div class="slist" id="re_soft">
            <h3>::相关软件::</h3>
            <div class="con"><a href="/movie_2004/index/qvodsetup.htm" target="_blank"><img src="http://pic.66fzl.com/newimages/qvod_logo.jpg" /></a><br />
              <a href="http://update.qvod.com/QvodPal.exe" target="_blank">Qvod解码器伴侣包</a><br />
              <a href="http://update.qvod.com/xpsp2patch.exe" target="_blank">XPSP2连接数限制补丁</a></div>
          </div>
        </div>
        <div class="r" id="mcon">
          <div class="s115">
            <form action="http://v.115.com/" method="get" target="_blank" id="s115" name="s115">
              <a href="http://v.115.com/" target="_blank"><img src="http://pic.66fzl.com/images/tom365_v115.gif" /></a>
              <input name="q" id="q" type="text" value="" class="txt" />
              <input name="" type="image" src="http://pic.66fzl.com/images/search_button.gif" alt="影视聚搜" />
            </form>
            <div class="hotag r">
    <script type="text/javascript" src="http://www.96693.com/tg/tom365/a4-txt/text.js"></script>
    </div>
          </div>
          <!---->
          <div id="shenfenid">
          <style type="text/css">
          #shenfenid{ line-height:24px; padding:0 8px 0 25px; border:1px solid #81B316; background:url(http://pic.66fzl.com/images/icon_01.gif) no-repeat 4px 4px; }
      #shenfenid a{ color:#F00; }
          </style>
          防止诈骗,赶紧使用“<a href="http://tool.115.com/live/idcard/" target="_blank">身份证真伪查询/身份证号码验证查询</a>”验明正身。</div>
         <!---->
          <div class="movie"><img src="http://pic.66fzl.com/imgs/liehuozhanche.jpg" class="mp" />
            <ul>
              <li>片  名:<strong id="mname">烈火战车[1国语版,2粤语版][BD版本]</strong></li>
              <li>年  代:1995</li>
              <li>地  区:香港</li>
              <li>类  型:<a href="../mlist/1_1.html">动作片</a></li>
              <li>导  演:尔冬升</li>
              <li>主  演:刘德华 梁咏琪 吴大维 秦沛</li>
              <li>上传日期:2011-01-12</li>
              
            </ul>
            <div class="cbn"><div id="m">
    <style>
    #m {border:10px solid #EEFFAD; width:369px; font-size:12px;}
    #m ul{ width:367px; height:41px; border:1px solid #C3EF2A}
    #m ul,#m li {  margin:0 ; padding:0 ; list-style:none;}
    #m li { float:left; width:170px; padding-left:13px; color:#72C603; overflow: hidden; line-height:20px;}
    #m a { color:#3B591B; text-decoration:none}
    #m a:hover { text-decoration:underline;}
    </style>
    <ul>
    <script type="text/javascript" src="http://www.96693.com/tg/tom365/b1-txt1/text.js"></script>
    </ul>
    </div></div><div class="mcn"><script  type="text/javascript" src="http://www.96693.com/tg/tom365/b2-59450/lunbo.js"></script></div>
            <div class="mcn"><img alt="" src="http://pic.66fzl.com/images/qvod.gif" width="20" height="20" align="middle" /><font color="#3B591B">  QVOD播放   <a href="/movie_2004/index/qvodsetup.htm" target="_blank">QVOD播放器下载>></a></font></div><ul class="mct">
            <li><a href="../index/p2p.htm?681493015%2F12B370FB9EEEF665E83ED6FE595490EB4D6D8CC3%2FFull.Throttle.1995.BDRip.AC3.CN.x264%5B%E7%83%88%E7%81%AB%E6%88%98%E8%BD%A6%5D.rmvb?4515?130?201102" target="_blank">[1]</a><li><a href="../index/p2p.htm?%0A681560833%2F89696304180404C2F1937E6D95234EC45402C652%2FFull.Throttle.1995.BDRip.AC3.HK.x264%5B%E7%83%88%E7%81%AB%E6%88%98%E8%BD%A6%5D.rmvb?4515?130?201102" target="_blank">[2]</a></ul>
            <div class="mcn"><img alt="" src="http://pic.66fzl.com/images/qvod.gif" width="20" height="20" align="middle" /><font color="#3B591B"> QVOD备用模式播放(正常模式无法点播时使用)</font></div><ul class="mct">
            <li><a href="../index/vod.htm?qvod%3A%2F%2F681493015%7CF7F2EF8FB2EE49E3E140BA28D7301E17494E16FE%7CFull.Throttle.1995.BDRip.AC3.CN.x264.rmvb%7C?4515" target="_blank">[1]</a><li><a href="../index/vod.htm?qvod%3A%2F%2F681560833%7CC047C871E39C06FD30B3F3A3F9D392F17A9082DC%7CFull.Throttle.1995.BDRip.AC3.HK.x264.rmvb%7C?4515" target="_blank">[2]</a></ul>
            <div class="text_gg"><script type="text/javascript" src="http://www.96693.com/tg/tom365/b3-59460/lunbo.js"></script><br>
    <script type="text/javascript" src="http://www.96693.com/tg/tom365/b4-txt2/text.js"></script></div>
    <!--
            <div class="copy">
            </div>
    你这样写也不行。因为我要从一堆的源码里取。
      

  6.   

    string html = @"<ul class=""mct"">
                                <li>
                                <a href=""../index/vod.htm?qvod%3A%2F%2F681493015%7CF7F2EF8FB2EE49E3E140BA28D7301E17494E16FE%7CFull.Throttle.1995.BDRip.AC3.CN.x264.rmvb%7C?4515"" target=""_blank"">[1]</a>
                                <li>
                                <a href=""../index/vod.htm?qvod%3A%2F%2F681560833%7CC047C871E39C06FD30B3F3A3F9D392F17A9082DC%7CFull.Throttle.1995.BDRip.AC3.HK.x264.rmvb%7C?4515"" target=""_blank"">[2]</a>
                                </ul>";
                foreach (Match m in Regex.Matches(html, @"(?is)<a\b.+?href=""(?<href>[^""]+)""\starget=""_blank"">(?<text>.+?)</a>"))
                {
                    Console.WriteLine(m.Groups["href"].Value);
                    Console.WriteLine(m.Groups["text"].Value);
                }
      

  7.   

            string result = "";
            string str = "<ul class=\"mct\"><li><a href=\"../index/vod.htm?qvod%3A%2F%2F681493015%7CF7F2EF8FB2EE49E3E140BA28D7301E17494E16FE%7CFull.Throttle.1995.BDRip.AC3.CN.x264.rmvb%7C?4515\" target=\"_blank\">[1]</a>"
                        + "<li><a href=\"../index/vod.htm?qvod%3A%2F%2F681560833%7CC047C871E39C06FD30B3F3A3F9D392F17A9082DC%7CFull.Throttle.1995.BDRip.AC3.HK.x264.rmvb%7C?4515\" target=\"_blank\">[2]</a></ul>";
            Regex reg = new Regex(@"(?is)<a[^>]*?href=(['""\s]?)(?<href>[^'""\s]*)\1[^>]*?>");
            MatchCollection match = reg.Matches(str);
            foreach (Match m in match)
            {
                result += m.Groups["href"].Value+"<br/>";
            }
            Response.Write(result);
      

  8.   

    不能以<a href="../index/vod.htm为条件吗?我只想取vod.htm?问号后的值。因为网页里有很多a标签
      

  9.   

    <a href=".*?/index/vod.htm\?(.*?)" target="_blank">\[(.*?)\]</a>
      

  10.   

    []是元字符
    转义
    string html = @"<ul class=""mct"">
                                <li>
                                <a href=""../index/vod.htm?qvod%3A%2F%2F681493015%7CF7F2EF8FB2EE49E3E140BA28D7301E17494E16FE%7CFull.Throttle.1995.BDRip.AC3.CN.x264.rmvb%7C?4515"" target=""_blank"">[1]</a>
                                <li>
                                <a href=""../index/vod.htm?qvod%3A%2F%2F681560833%7CC047C871E39C06FD30B3F3A3F9D392F17A9082DC%7CFull.Throttle.1995.BDRip.AC3.HK.x264.rmvb%7C?4515"" target=""_blank"">[2]</a>
                                <li><a href=""xx.html"" target=""_blank"">xxx</a></li>
                                <li><a href=""yy.html"" target=""_blank"">[yyyy</a></li>
                                </ul>";
                foreach (Match m in Regex.Matches(html, @"<a href=""(?<href>.*?)"" target=""_blank"">(?<text>\[.*?\])</a>"))
                {
                    Console.WriteLine(m.Groups["href"].Value);
                    Console.WriteLine(m.Groups["text"].Value);
                }
      

  11.   


    void Main()
    {
      string html=@"<div id=""main"">
      <div class=""l side"">
      <div id=""tools"">
      <h3>::实用工具::</h3>
      <ul>
      <li><a href=""http://tool.115.com/live/speed"" target=""_blank"">上网测速</a></li>
      <li><a href=""http://tool.115.com/shouji/"" target=""_blank"">手机查询</a></li>
      <li><a href=""http://tool.115.com/live/huoche/"" target=""_blank"">火车时刻</a></li>
      <li><a href=""http://tool.115.com/ip/"" target=""_blank"">I P 地址</a></li>
      <li><a href=""http://aq.115.com"" target=""_blank"">免费杀毒</a></li>
      <li><a href=""http://tool.115.com/live/express/"" target=""_blank"">快递查询</a></li>
      <li><a href=""http://tool.115.com/tianqi/"" target=""_blank"">天气预报</a></li>
      <li><a href=""http://tool.115.com/live/fanyi/"" target=""_blank"">在线翻译</a></li>
      <li><a href=""http://tool.115.com/live/ditu/"" target=""_blank"">城市地图</a></li>
      <li><a href=""http://tool.115.com/youbian/"" target=""_blank"">邮编区号</a></li>
      </ul>
      </div>
      <div id=""msrc"">
      <h3>::影片搜索::</h3>
      <form name=""form"" action=""/files/search.php"" method=""post"" target=""_blank"">
      选择类型 <span class=""select"">
      <select name=""typeid"">
      <option value=""title"">电影名称</option>
      <option value=""actor"">演员名称</option>
      </select>
      </span>
      <div id=""search"">
    关键字 <input type=""text"" name=""keyword"" class=""k"" />
      <input type=""submit"" value=""影片搜索"" onClick=""if (form.keyword.value.length==0) {alert('请输入关键字!');return false;}"" class=""btn"" /></div>
      <div id=""search_auto""></div>
      </form>
      </div>
    <!--
      <div class=""slist"" id=""new"">
      <h3>::最近更新::</h3>
      <ul>
      <script src=""../js/news.js""></script>
      </ul>
      </div>
    -->
      <div class=""slist"" id=""order"">  </div>
      <div class=""slist"" id=""re_soft"">
      <h3>::相关软件::</h3>
      <div class=""con""><a href=""/movie_2004/index/qvodsetup.htm"" target=""_blank""><img src=""http://pic.66fzl.com/newimages/qvod_logo.jpg"" /></a><br />
      <a href=""http://update.qvod.com/QvodPal.exe"" target=""_blank"">Qvod解码器伴侣包</a><br />
      <a href=""http://update.qvod.com/xpsp2patch.exe"" target=""_blank"">XPSP2连接数限制补丁</a></div>
      </div>
      </div>
      <div class=""r"" id=""mcon"">
      <div class=""s115"">
      <form action=""http://v.115.com/"" method=""get"" target=""_blank"" id=""s115"" name=""s115"">
      <a href=""http://v.115.com/"" target=""_blank""><img src=""http://pic.66fzl.com/images/tom365_v115.gif"" /></a>
      <input name=""q"" id=""q"" type=""text"" value="""" class=""txt"" />
      <input name="""" type=""image"" src=""http://pic.66fzl.com/images/search_button.gif"" alt=""影视聚搜"" />
      </form>
      <div class=""hotag r"">
    <script type=""text/javascript"" src=""http://www.96693.com/tg/tom365/a4-txt/text.js""></script>
    </div>
      </div>
      <!---->
      <div id=""shenfenid"">
      <style type=""text/css"">
      #shenfenid{ line-height:24px; padding:0 8px 0 25px; border:1px solid #81B316; background:url(http://pic.66fzl.com/images/icon_01.gif) no-repeat 4px 4px; }
    #shenfenid a{ color:#F00; }
      </style>
      防止诈骗,赶紧使用“<a href=""http://tool.115.com/live/idcard/"" target=""_blank"">身份证真伪查询/身份证号码验证查询</a>”验明正身。</div>
      <!---->
      <div class=""movie""><img src=""http://pic.66fzl.com/imgs/liehuozhanche.jpg"" class=""mp"" />
      <ul>
      <li>片  名:<strong id=""mname"">烈火战车[1国语版,2粤语版][BD版本]</strong></li>
      <li>年  代:1995</li>
      <li>地  区:香港</li>
      <li>类  型:<a href=""../mlist/1_1.html"">动作片</a></li>
      <li>导  演:尔冬升</li>
      <li>主  演:刘德华 梁咏琪 吴大维 秦沛</li>
      <li>上传日期:2011-01-12</li>

      </ul>
      <div class=""cbn""><div id=""m"">
    <style>
    #m {border:10px solid #EEFFAD; width:369px; font-size:12px;}
    #m ul{ width:367px; height:41px; border:1px solid #C3EF2A}
    #m ul,#m li { margin:0 ; padding:0 ; list-style:none;}
    #m li { float:left; width:170px; padding-left:13px; color:#72C603; overflow: hidden; line-height:20px;}
    #m a { color:#3B591B; text-decoration:none}
    #m a:hover { text-decoration:underline;}
    </style>
    <ul>
    <script type=""text/javascript"" src=""http://www.96693.com/tg/tom365/b1-txt1/text.js""></script>
    </ul>
    </div></div><div class=""mcn""><script type=""text/javascript"" src=""http://www.96693.com/tg/tom365/b2-59450/lunbo.js""></script></div>
      <div class=""mcn""><img alt="""" src=""http://pic.66fzl.com/images/qvod.gif"" width=""20"" height=""20"" align=""middle"" /><font color=""#3B591B""> QVOD播放 <a href=""/movie_2004/index/qvodsetup.htm"" target=""_blank"">QVOD播放器下载>></a></font></div><ul class=""mct"">
      <li><a href=""../index/p2p.htm?681493015%2F12B370FB9EEEF665E83ED6FE595490EB4D6D8CC3%2FFull.Throttle.1995.BDRip.AC3.CN.x264%5B%E7%83%88%E7%81%AB%E6%88%98%E8%BD%A6%5D.rmvb?4515?130?201102"" target=""_blank"">[1]</a><li><a href=""../index/p2p.htm?%0A681560833%2F89696304180404C2F1937E6D95234EC45402C652%2FFull.Throttle.1995.BDRip.AC3.HK.x264%5B%E7%83%88%E7%81%AB%E6%88%98%E8%BD%A6%5D.rmvb?4515?130?201102"" target=""_blank"">[2]</a></ul>
      <div class=""mcn""><img alt="""" src=""http://pic.66fzl.com/images/qvod.gif"" width=""20"" height=""20"" align=""middle"" /><font color=""#3B591B"">  QVOD备用模式播放(正常模式无法点播时使用)</font></div><ul class=""mct"">
      <li><a href=""../index/vod.htm?qvod%3A%2F%2F681493015%7CF7F2EF8FB2EE49E3E140BA28D7301E17494E16FE%7CFull.Throttle.1995.BDRip.AC3.CN.x264.rmvb%7C?4515"" target=""_blank"">[1]</a><li><a href=""../index/vod.htm?qvod%3A%2F%2F681560833%7CC047C871E39C06FD30B3F3A3F9D392F17A9082DC%7CFull.Throttle.1995.BDRip.AC3.HK.x264.rmvb%7C?4515"" target=""_blank"">[2]</a></ul>
      <div class=""text_gg""><script type=""text/javascript"" src=""http://www.96693.com/tg/tom365/b3-59460/lunbo.js""></script><br>
    <script type=""text/javascript"" src=""http://www.96693.com/tg/tom365/b4-txt2/text.js""></script></div>
    <!--
      <div class=""copy"">
      </div>
    ";
    foreach(Match m in  Regex.Matches(html,@"<a[^>]*?href=(['""])?(?<href>[^'""]+)\1[^>]*>"))
    {
      Console.WriteLine(m.Groups["href"].Value);
    }
    }/*
    http://tool.115.com/live/speed
    http://tool.115.com/shouji/
    http://tool.115.com/live/huoche/
    http://tool.115.com/ip/
    http://aq.115.com
    http://tool.115.com/live/express/
    http://tool.115.com/tianqi/
    http://tool.115.com/live/fanyi/
    http://tool.115.com/live/ditu/
    http://tool.115.com/youbian/
    /movie_2004/index/qvodsetup.htm
    http://update.qvod.com/QvodPal.exe
    http://update.qvod.com/xpsp2patch.exe
    http://v.115.com/
    http://tool.115.com/live/idcard/
    ../mlist/1_1.html
    /movie_2004/index/qvodsetup.htm
    ../index/p2p.htm?681493015%2F12B370FB9EEEF665E83ED6FE595490EB4D6D8CC3%2FFull.Throttle.1995.BDRip.AC3.CN.x264%5B%E7%83%88%E7%81%AB%E6%88%98%E8%BD%A6%5D.rmvb?4515?130?201102
    ../index/p2p.htm?%0A681560833%2F89696304180404C2F1937E6D95234EC45402C652%2FFull.Throttle.1995.BDRip.AC3.HK.x264%5B%E7%83%88%E7%81%AB%E6%88%98%E8%BD%A6%5D.rmvb?4515?130?201102
    ../index/vod.htm?qvod%3A%2F%2F681493015%7CF7F2EF8FB2EE49E3E140BA28D7301E17494E16FE%7CFull.Throttle.1995.BDRip.AC3.CN.x264.rmvb%7C?4515
    ../index/vod.htm?qvod%3A%2F%2F681560833%7CC047C871E39C06FD30B3F3A3F9D392F17A9082DC%7CFull.Throttle.1995.BDRip.AC3.HK.x264.rmvb%7C?4515*/
      

  12.   

    没。不是无视你。呵呵。我这测试了。用你的方法取出来42个值。有很多都是用不到的。本来取出两个就行了。这些源码里只有两个<a href="../index/vod.htm?
      

  13.   

    只有两条有用的数据。我只想要<a href="../index/vod.htm?以后的href
      

  14.   

    (?<=<a href=".*?/index/vod.htm\?).*?(?=" target="_blank">\[.*?\]</a>)只有两个的,还是按你原来的改的