1、获取div内容
string str = "tt<u>ss</u><div id=\"test\"><div><a>fds</a></div></div>";
Regex reg = new Regex(@"(?is)<div\s+id=""test"">(?><div[^>]*>(?<o>)|</div>(?<-o>)|(?:(?!</?div\b).)*)*(?(o)(?!))</div>");
Match m = reg.Match(str);
if (m.Success)
{
Response.Write(m.Value);
}
2、获取div内容
string str = "tt<u>ss</u><div id=\"test\"><div><a>fds</a></div></div>";
Regex reg = new Regex(@"(?is)<div\s*id=""test"">((?<Open><div>)|(?<-Open></div>)|.*?)*?(?(Open)(?!))</div>");
Match m = reg.Match(str);
if (m.Success)
{
Response.Write(m.Value);
}