日期:2014-05-17  浏览次数:20795 次

救急,跪求一正则表达式,根据条件获取超链接的链接字符串。
比如:<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这个字符串
------解决方案--------------------

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
*/

------解决方案--------------------
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);   
}   

------解决方案--------------------
http://itunes.apple.com/cn/app/[^"'>]*