Asp.net正则获取html内容

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);
}
上一篇:Response.Clear()和Response.ClearContent()区别


下一篇:DataTable的Merge使用