jQuery javascript regex Replace <br> with \n -


how write regex replace <br /> or <br> \n. i'm trying move text div textarea, don't want <br>'s show in textarea, want replace \n.

var str = document.getelementbyid('mydiv').innerhtml; document.getelementbyid('mytextarea').innerhtml = str.replace(/<br\s*[\/]?>/gi, "\n"); 

or using jquery:

var str = $("#mydiv").html(); var regex = /<br\s*[\/]?>/gi; $("#mydiv").html(str.replace(regex, "\n")); 

example

edit: added i flag

edit2: can use /<br[^>]*>/gi match between br , slash if have example <br class="clear" />


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -