新手问题,大家帮帮忙!
如何把这段    <a href="viewthread.php?tid=3653053&amp;extra=page%3D1">曼联球迷写的打油诗,太有才了!</a>如何编译:(?is)<a(?:(?!>).)*>(['""]?)>\1[^>]*>(?:(?!</a).)*</a>这是本人自己编译的,请各位指点一下!看看错在那了!

解决方案 »

  1.   

    如果你需要截取a标签之间的内容,用这个即可: string source = @"<a href=""viewthread.php?tid=3653053&amp;extra=page%3D1"">曼联球迷写的打油诗,太有才了!</a>";
                    string patten = @"(?is)<a\s*href=(['""])[^'""]+\1>(?<content>[^<]+)</a>";
                    Regex reg = new Regex(patten);
                    MatchCollection collection = reg.Matches(source);
                    MessageBox.Show(collection.Count.ToString());
                    if (collection.Count > 0)
                    {
                        foreach (Match m in collection)
                        {
                            MessageBox.Show(m.Groups["content"].Value);                    }
                    }
                    else
                    {
                        MessageBox.Show("No Match");
                    }
    结果:曼联球迷写的打油诗,太有才了!
      

  2.   

    Regex reg = new Regex(@"(?is)<a[^>]*>(.*?)</a>");
    MatchCollection mc = reg.Matches(yourStr);
    foreach(Match m in mc)
    {
        richtextbox2.Text = m.Groups[1].Value + "\n";
    }
      

  3.   

           string str=@"<a href=""viewthread.php?tid=3653053&amp;extra=page%3D1"">曼联球迷写的打油诗,太有才了!</a>";
           Regex reg = new Regex(@"(?is)<a[^>]*?href=(['""\s]?)(?<href>[^'""\s]+)\1[^>]*?>(?<txt>.*?)</a>");
           foreach (Match m in reg.Matches(str))
               Response.Write(m.Groups["href"].Value + "<br>" + m.Groups["txt"].Value);
    /*
    viewthread.php?tid=3653053&extra=page%3D1
    曼联球迷写的打油诗,太有才了! 
    */
      

  4.   

    http://bbs.mso2011.com/forumdisplay.php?fid=68请各位专家解密:如何用正则式来提取网页里的标题与链接地址!