首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

救灾,跪求一正则表达式,根据条件获取超链接的链接字符串

2013-01-04 
救急,跪求一正则表达式,根据条件获取超链接的链接字符串。比如:a hrefhttp://itunes.apple.com/cn/app/t

救急,跪求一正则表达式,根据条件获取超链接的链接字符串。
比如:<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/[^"'>]*

热点排行