Here is a sample content:
<p> so so so </p>
<div> whatever</div
<p> another paragraph </p>
<div> forever </div>
<p> first of last </p>
<p> second of last </p>
How can I match the last two paragraphs (or any number of consecutive paragraphs) at the end of the above document?
The match output I want is:
<p> first of last </p>
<p> second of last </p>
I tried /(<p>[sS]*?</p>[s]*)$/g
, but the lazy matching is not working as expected, it sucks all the p tags in between, and matches from the first opening p tag it encounters up to the end of the document.
Note: there might not be paragraphs at the end at all, the regex should not match if there are no paragraphs at the end.
question from:
https://stackoverflow.com/questions/65852603/how-can-i-match-a-bunch-of-p-tags-at-the-end-of-an-html-document-with-javascript 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…