开发者

Regex to match last paragraph tag and contents

开发者 https://www.devze.com 2023-03-30 02:05 出处:网络
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..

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

精彩评论

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