比如:<a href="http://itunes.apple.com/cn/app/the-abolition-man-the-great/id392965200?mt=8">
 The Abolition of Man and The Great Divorce (by C.S. Lewis) (UNABRIDGED AUDIOBOOK) : Blackstone Audio...
</a>
请问我要获取所有链接地址以 http://itunes.apple.com/cn/app/开头的链接的链接地址的正则表达式怎么写?
我最终要获取的就是 http://itunes.apple.com/cn/app/the-abolition-man-the-great/id392965200?mt=8这个字符串

解决方案 »

  1.   


    void Main()
    {
       string html=@"<a href=""http://itunes.apple.com/cn/app/the-abolition-man-the-great/id392965200?mt=8"">
     The Abolition of Man and The Great Divorce (by C.S. Lewis) (UNABRIDGED AUDIOBOOK) : Blackstone Audio...
    </a>";
     
    foreach(Match m in  Regex.Matches(html,@"http://itunes.apple.com/cn/app/[^""]*"))
    {
      Console.WriteLine(m.Value);
    }
    }/*
    http://itunes.apple.com/cn/app/the-abolition-man-the-great/id392965200?mt=8
    */
      

  2.   

    MatchCollection mc= Regex.Matches(str, @" <a[^> ]*href=([ ' " "]?)(? <url> [^ ' " "> \s]*)\1?[^> ]*> (? <text> [^ <]*) </a> ", RegexOptions.IgnoreCase);   
    foreach (Match m in mc)   
    {   
      Response.Write(m.Groups[ "url "].Value);   
      Response.Write(m.Groups[ "text "].Value);   
    }   
      

  3.   

    http://itunes.apple.com/cn/app/[^"'>]*
      

  4.   

    谢谢各位。顺便问一下,根据超链接的class获取链接地址怎样写?例如<a class="paginate-more" href="http://itunes.apple.com/cn/genre/mobile-software-applications/id6018?mt=8&letter=A&page=2#page">Next</a>
      

  5.   


    void Main()
    {
       string html=@"<a class=""paginate-more"" href=""http://itunes.apple.com/cn/genre/mobile-software-applications/id6018?mt=8&letter=A&page=2#page"">Next</a>";
     
    foreach(Match m in  Regex.Matches(html,@"(?is)<a([^>]*)class=(['""]?)paginate-more\2\1href=\2(?<url>[^'""]*)\2>"))
    {
      Console.WriteLine(m.Groups["url"].Value);
    }
    }/*
    http://itunes.apple.com/cn/genre/mobile-software-applications/id6018?mt=8&letter=A&page=2#page
    */