string YourString = "<xxx xxx='xx' class='title'>YYYY</xxx>"; Regex r = new Regex(@"<[^>]+class\s*=\s*(['""]?)title\1[^>]*>(?<text>[^<]+)<[^>]+>", RegexOptions.IgnoreCase); Match m = r.Match(YourString); if (m.Success) { string s = m.Groups["text"].Value; Console.WriteLine(s); }
string YourString = "<xxx xxx='xx' class='title'>YYYY</xxx>";
Regex r = new Regex(@"<[^>]+class\s*=\s*(['""]?)title\1[^>]*>(?<text>[^<]+)<[^>]+>", RegexOptions.IgnoreCase); Match m = r.Match(YourString);
if (m.Success)
{
string s = m.Groups["text"].Value;
Console.WriteLine(s);
}
可是,能给我们详细讲解一下为什么这么写么?我看得不太懂。