开发者

Get html content with RegEx between several tags

开发者 https://www.devze.com 2023-02-25 04:26 出处:网络
For example there are some html tags <div id=\"test\"><div><div>testtest</div></div></div&开发者_JAVA百科gt;</div></div></div>

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

精彩评论

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