我用webclient down  过来的页面中有很多的
<cite>
<a c="1" href="http://www.deyi.com/space-uid-48025.html" mid="DRKtpIhCmmXZaoEXYKIYOLWYaWQEZWDH" id="ajaxid_0.7930081481989826">XXXXXXXXXXXX</a>
</cite>
我现在想把 这个 cite 的 a标签的内容提取出来  应该如何写啊??? 求教了  不会搞正则啊!!!

解决方案 »

  1.   

    <cite>[\s\S]*?</cite>这就把a标签和里面的内容全弄出来了,然后用regex就行啦。
      

  2.   

                string str = @"<cite>
    <a c=""1"" href=""http://www.deyi.com/space-uid-48025.html"" mid=""DRKtpIhCmmXZaoEXYKIYOLWYaWQEZWDH"" id=""ajaxid_0.7930081481989826"">XXXXXXXXXXXX</a>
    </cite><cite>
    <a c=""1"" href=""http://www.deyi.com/space-uid-48025.html"" mid=""DRKtpIhCmmXZaoEXYKIYOLWYaWQEZWDH"" id=""ajaxid_0.7930081481989826"">AAAAAAAAAAAA</a>
    </cite>";
                Regex reg = new Regex(@"(?is)(?<=<cite>(?:(?!</?cite).)*)<a[^>]*?>(.*?)</a>");
                foreach (Match m in reg.Matches(str))
                    Console.WriteLine(m.Groups[1].Value);
      

  3.   

    我也做过类似的东东,不过a标签是取不出来的 像这样 ("<a id=\"[\\w\\d]\">","</a>")   这样取不出来所以建议取<cite>的id ,如果没有的话那更好整 ("<cite>","</cite>")你试试,我也是刚学正则不知道行不行
      

  4.   

    前两天刚回了一个类似的可做借鉴 你这个比那个要简化些//取出文档中所有a的html编码和id值
    private ArrayList GetHyperlinkElemID(string text)
    {
        ArrayList al = new ArrayList();
        Regex reg = new Regex(@"<a([^>]+)?\s+id=('|"")([\w]+)('|"")\s*([^>]+)?>([^<>]*((?<G><[\w]+\s*[^>]*>)[^<>]*)+((?<-G></[\w]+>)[^<>]*)+)*</a>"
            , RegexOptions.IgnoreCase | RegexOptions.Multiline);
        foreach (Match mt in reg.Matches(text))
        {
            string a = mt.Value;//这里是<a>的html代码 展示用 没保存
            al.Add(mt.Result("$3"));//这里是id
        }
        return al;
    }
      

  5.   

    private ArrayList GetHyperlinkElemID(string text)
    {
      ArrayList al = new ArrayList();
      Regex reg = new Regex(@"<a([^>]+)?\s+id=('|"")([\w]+)('|"")\s*([^>]+)?>([^<>]*((?<G><[\w]+\s*[^>]*>)[^<>]*)+((?<-G></[\w]+>)[^<>]*)+)*</a>"
      , RegexOptions.IgnoreCase | RegexOptions.Multiline);
      foreach (Match mt in reg.Matches(text))
      {
      string a = mt.Value;//这里是<a>的html代码 展示用 没保存
      al.Add(mt.Result("$3"));//这里是id
      }
      return al;
    }