Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html textarea replace br tag to \n

I need to edit row's cell in table with using new lines characters. Editation of these cells are make by textarea with jQuery. Problem is, that textarea using \n for new line, but html page using br tag.

There is my code:

$('#id_textarea').val(cell_string.replace(/<br>\*/gi,'\n'));

I know, that string has br tag likes (NOTE-1):

<br></br>

I tried:

$('#id_textarea').val(cell_string.replace(/**<br></br>**\*/gi,'\n'));

But still cannot understand, how the regular expression works.

And there is picture of my issue.

NOTE-1 - these br tags are make by:

content = content.replace(/\n/g, "<br>");

IN DB there is:

<br>

In Firefox:

<br></br>

In Chrome:

<br>

Why?

like image 566
Jerry1 Avatar asked Mar 21 '23 08:03

Jerry1


1 Answers

Your regex is not right, try:

$('#id_textarea').val(cell_string.replace(/<br *\/?>/gi, '\n'));

THE DEMO.

like image 101
xdazz Avatar answered Mar 22 '23 22:03

xdazz