想要从<p class="a"><a href="http://www.aa.com/123456" class="info" title="ABC">ABC</a></p>中取出超链接的内容ABC,其中class="info"是唯一的,请问正则怎么写,我自己写的取不出:
string a="";
string pattern = @"(?is)<a[^>]*?class=""info"" [^>]*>([\s\S]*)</a>";
MatchCollection mc = Regex.Matches(str, pattern);
foreach (Match m in mc)
{
a += m.Groups[1].Value.ToString();
}
return a;
string a="";
string pattern = @"(?is)<a[^>]*?class=""info"" [^>]*>([\s\S]*)</a>";
MatchCollection mc = Regex.Matches(str, pattern);
foreach (Match m in mc)
{
a += m.Groups[1].Value.ToString();
}
return a;
Regex reg = new Regex(@"(?is)<a[^>]*?class=(['""\s]?)info\1[^>]*?>(.*?)</a>");
foreach (Match m in reg.Matches(str))
Console.WriteLine(m.Groups[2].Value);
string pattern = @"(?i)(?<=<a[^>]*?class=""info""[^>]*?>)[^<>]+(?=</a>)";
MatchCollection mc = Regex.Matches(str, pattern);
foreach (Match m in mc)
{
a += m.Value;
}
return a;