"TEXT <p>TEST1</p><br><div> <p>TEST2</p></div>"
(string, not html)
Here i am trying to capture the last <p>
tag until </p></div>
. (Edit: NOT just the text between, I'm including the actual string tags)
How do you start from the end from where </p><div>
is to the next prior <p>
that contains "TEST2" instead of "TEST1"? I am running into this problem because the first match (going forwards) contains the match I am looking for, rather than being a separate match.
I know I can grab the index of the </p></div>
and then loop backwards until I find a <p>
, but this seems inefficient. I also know RegEx in JavaScript does not allow you to do search from end of string based on this answer (javascript regex search from end of string to begining) , so just posting because I am unaware of more optimal solutions.