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);
        }

 

posted @ 2016-07-14 09:04  WebApi  阅读(928)  评论(0编辑  收藏  举报
CopyRight © 博客园 WebAPI