62,046
社区成员
发帖
与我相关
我的任务
分享
void Main()
{
string html=@"<a onMouseDown=""return inpmv(1340);""
href=""/p-4074.html"" target=""docin_p_end"">
<a target=""docin_p_end"" href=""/p-41751927.html"" title=""影响中国孩子的名人故事(三)"" onMouseDown=""return inpmv(1293);"">
<a target=""docin_p_end"" href=""/p-19312068.html"" title=""世界杯走过的路"" onMouseDown=""return inpmv(1293);"">";
foreach(Match m in Regex.Matches(html,@"(?i)<a[^>]*?href=(['""\s]?)(?<href>[^'""\s]+)\1[^>]*?>"))
{
Console.WriteLine("http://www.docin.com"+m.Groups["href"].Value);
}
/*
http://www.docin.com/p-4074.html
http://www.docin.com/p-41751927.html
http://www.docin.com/p-19312068.html
*/
}
string str = @"<a onMouseDown=""return inpmv(1340);"" href=""/p-4074.html"" target=""docin_p_end"">
<a target=""docin_p_end"" href=""/p-41751927.html"" title=""影响中国孩子的名人故事(三)"" onMouseDown=""return inpmv(1293);"">
<a target=""docin_p_end"" href=""/p-41755.html"" title=""影响中国孩子的名人故事(三)"" onMouseDown=""return inpmv(1293);"">
<a target=""docin_p_end"" href=""/p-19312068.html"" title=""世界杯走过的路"" onMouseDown=""return inpmv(1293);"">";
Regex reg = new Regex(@"(?is)<a[^>]*?href=(['""]?)(/p-(?:\d{4}|\d{8})\.html)\1[^>]*?>");
foreach (Match m in reg.Matches(str))
Console.WriteLine("http://www.docin.com" + m.Groups[2].Value);
Console.ReadLine();
/*
http://www.docin.com/p-4074.html
http://www.docin.com/p-41751927.html
http://www.docin.com/p-19312068.html
*/