<div class="thumbtitle">
                                    <a target="_blank" title="我们" href="/play?docid=-5124753746676723195&url=http://v.youku.com/v_show/id_XMTg1NzI3NzA0.html&query=%E6%88%91%E4%BB%AC&pos=23&keyfrom=album.normalResults"
                                        onclick="_reqlog('album','album.playNormalVideo','normalPos=23&playfrom=title&queryHasNormalPlay=%E6%88%91%E4%BB%AC')">
                                        <span class="hl">我们</span></a>
                                </div>
匹配<a title >和<a>内容</a>麻烦各位帮我解决一下,这个我实在搞不好!!!取A里面的TITTLE和内容!谢谢各位了!

解决方案 »

  1.   

    Regex regex = new Regex("<a.*?href=\"(?<href>.*?)\".*?title=\"(?<title>.*?)\".*?>", RegexOptions.Compiled);
    可以取到 href 和title 
      

  2.   

    只取到了TITLE,A标签里面的<a></a>里面的文本内容完全没有啊!!
      

  3.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.IO;
    namespace sxLdfang
    {
        class Program
        {
            static void Main(string[] args)
            {
                string html = @"<div class=""thumbtitle"">
      <a target=""_blank"" title=""我们"" href=""/play?docid=-5124753746676723195&url=http://v.youku.com/v_show/id_XMTg1NzI3NzA0.html&query=%E6%88%91%E4%BB%AC&pos=23&keyfrom=album.normalResults""
      onclick=""_reqlog('album','album.playNormalVideo','normalPos=23&playfrom=title&queryHasNormalPlay=%E6%88%91%E4%BB%AC')"">
      <span class=""hl"">我们</span></a>
      </div>
     
    ";
                string pattern = @"(?isn)<a\s+((?!title\s*=)\S*\s+)*title\s*=\s*(?<q>['""])?(?<title>(?(q)((?!\k<q>).)*|[^>\s]*))[^>]*>(?<text>.*?)</a>";
                MatchCollection mc = Regex.Matches(html, pattern);
                foreach (Match m in mc)
                {
                    Console.WriteLine("     title:" + m.Groups["title"].Value);
                    Console.WriteLine("      text:" + m.Groups["text"].Value);
                    Console.WriteLine();
                }
                Console.ReadKey();
            }
        }
    }
    运行结果:
         title:我们
          text:
      <span class="hl">我们</span>
      

  4.   

     string str = @"<div class=""thumbtitle"">
      <a target=""_blank"" title=""我们"" href=""/play?docid=-5124753746676723195&url=http://v.youku.com/v_show/id_XMTg1NzI3NzA0.html&query=%E6%88%91%E4%BB%AC&pos=23&keyfrom=album.normalResults""
      onclick=""_reqlog('album','album.playNormalVideo','normalPos=23&playfrom=title&queryHasNormalPlay=%E6%88%91%E4%BB%AC')"">
      <span class=""hl"">我们</span></a>
      </div>";
                Regex reg = new Regex(@"(?is)<a[^>]*?title=(['""]?)(?<title>[^'""]+)\1[^>]*?>(?<content>(?:(?!</?a).)*)");
                foreach (Match m in reg.Matches(str))
                    Response.Write(m.Groups["title"].Value + "==" + m.Groups["content"].Value);
    /*
    我们
    <span class="hl">我们</span>
    */