I am trying to get rid of all the extra <br>
in the first paragraph and last paragraph.
For example:
st = "<p><br><br><br><br>apple</p>
<p>bananas</p>
<p>orange<br><br><br><br><br></p>
<p>tomatoes</p>
<p>berry<br><br><br><br><br><br></p>"
I'm hoping to end up with this:
"<p>apple</p>
<p>bananas</p>
<p>orange<br><br><br><br><br></p>
<p>tomatoes</p>
<p>berry</p>"
My goal is to leave the <br>
middle paragraphs (ex. orange paragraph) alone and remove all the first paragraph <br>
and all the end the last paragraph.
I've tried doing this regex:
st.sub(/^((<p>)|<br( \/)?>)*|(<p>|<br( \/)?>|< \/p>)*$/, '')
I get this:
=> "<p>apple</p>
<p>bananas</p>
<p>orange<br><br><br><br><br></p>
<p>tomatoes</p>
<p>berry<br><br><br><br><br><br></p>"
I am unable to delete the last paragraph repeating <br>
.