开发者

Get html content with RegEx between several tags

For example there are some html tags <div id="test"><div><div>testtest</div></div></div&开发者_JAVA百科gt;</div></div></div>

From that html, I need to get this <div id="test"><div><div>testtest</div></div></div>

Current regex /<div id=\"test\">.*(</div>){3}/gim


Since you have the specific requirement of needing exactly three closing tags, this regular expression should do the trick:

(<div.*?>)+.*?(</div>){3}

The trick here is to use the lazy star (*?) to keep the catch-all (.) character from matching more than you'd like.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜