2

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 should 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.

Community
  • 1
  • 1
Scott
  • 21
  • 1
  • 2

1 Answers1

1

The following regular expression using lookahead will work:

<p>(.*?)</p>(?!\s*<p>)
beny23
  • 34,390
  • 5
  • 82
  • 85