日期:2014-05-20 浏览次数:20416 次
string str = @"<em>[<a href="""">经验窍门</a>]</em><a href=""thjy.co"" onClick=""atarget(this)"" class=""xst"">sfasdf</a> <img src=""static/image/common/hot_3.gif"" alt=""heatlevel"" title=""3 级热门"" align=""absmiddle""> <em>[<a href="""">经验窍门</a>]</em><a href=""bbs.thjy.co"" onClick=""atarget(this)"" class=""xst"">sfasdf</a> <img src=""static/image/common/hot_3.gif"" alt=""heatlevel"" title=""3 级热门"" align=""absmiddle""> <em>[<a href="""">经验窍门</a>]</em><a href=""test.thjy.co"" onClick=""atarget(this)"" class=""xst"">sfasdf</a> <img src=""static/image/common/hot_3.gif"" alt=""heatlevel"" title=""3 级热门"" align=""absmiddle"">"; Regex reg = new Regex(@"(?i)<a\s*href=""(?<url>[^""]+)""\s+onclick=""atarget\(this\)"""); MatchCollection mc = reg.Matches(str); foreach (Match m in mc) { Console.WriteLine(m.Groups["url"].Value); }
------解决方案--------------------
Regex reg = new Regex(@"(?i)<a[^>]*?href=(['""\s]?)(?<url>[^\s'""]+)\1\s+onclick=(['""\s]?)atarget\(this\)\2");