具有动态<textarea>的正则表达式

How can I do this with the JS replace() method:

  • Make change to <p>$1</p>
  • Change single to <br>
  • Then back again. I think I have this part, see the JS at the bottom.

Example HTML:

<p>Hello</p><p>Wor<br>ld</p>

The <textarea> would look like:

Hello

Wor
ld

So, how can I achieve this? It's an AJAX form where when you click on this div it changes to a <textarea> and back, and fourth, etc. So, I need to it to go from <p>s and <br>s to and . For the going to <textarea> from HTML I have:

$(this).html().replace(/\s?<\/?(p|br\s?\/?)>\s?/g,"
")

to Victor, and others,

I tried this code to convert it back, but it gave me this in return (the ... is just a lot more text)

$(this).html().replace(/
/g, "<br>").replace(/<br><br>(.*)?/g, "<p>$1</p>");

gave me:

<div class="editable" data-name="notes-content" data-type="textarea">
“Time Certain” indicates that an item will not be heard by Council prior to the time certain
.<p>Communications items are three minutes each. ... 
<br><br>The * indicates an emergency ... 
<br><br>Check our Web site: www.portlandonline.com
<br>
</p>
</div>

If you notice, it didnt wrap the first line, and its not wrapping them in <p>s, just the entire thing, i need it all in <p>s

Here you go:

$(this).html().replace(/
/g, "<br>").replace(/<br><br>(.*)?/g, "<p>$1</p>");

How about this (version #4):

$(this).html().replace(/ /g, "<br>").replace(/(.+?)<br><br>/g, "<p>$1</p>");