日期:2014-05-18 浏览次数:20970 次
string html = @"<div class=""c"" id=""C_3448822217297814""> <a href=""/u/256822820?vt=4&""> Baby_MR_GaG </a> 。。。。。。。。。。。。。。。。。好多1 </div> <div></div> <div class=""c"" id=""C_3448822217297814""> <a href=""/u/256822820?vt=4&""> Baby_MR_GaG </a> 。。。。。。。。。。。。。。。。。好多1 </div> <div></div> <div class=""c"" id=""C_3448822217297814""> <a href=""/u/256822860?vt=4&""> Baby_MR_GaG </a> 。。。。。。。。。。。。。。。。。好多1 </div> <div></div>"; string pattern = @"(?is)<a\s*href=""[^""]+""[^>]*>(.*?)</a>"; MatchCollection mc = Regex.Matches(html, pattern); foreach (Match m in mc) { Console.WriteLine(m.Group[1].Value.Trim());//去掉收尾空格 } //或者 string pattern = @"(?is)(?<=<a\s*href=""[^""]+""[^>]*>).*?(?=</a>)"; MatchCollection mc = Regex.Matches(html, pattern); foreach (Match m in mc) { Console.WriteLine(m.Value.Trim());//去掉收尾空格 } /* Baby_MR_GaG Baby_MR_GaG Baby_MR_GaG */
------解决方案--------------------