开发者

Regex to match last paragraph tag and contents

I'm trying to write a regex that will remove the last paragraph tags in a string, and all the content between. I can match the paragraph tags fine, but not the last..

Example:

<p>This shouldnt get selected</p>
<p>This either</p>
<p>Bleh</p>

What shoul开发者_运维技巧d get matched

<p>Bleh</p>

I found some code that matched the last set of square brackets here, regex to match contents of last [bracketed text] , but have been unable to modify it to work with paragraph tags.


The following regular expression using lookahead will work:

<p>(.*?)</p>(?!\s*<p>)
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜