Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacing double backslashes in JavaScript -- line breaks in a textarea

I'm having trouble getting my line breaks to show up in a textarea. The data I'm receiving contains double backslashes on line breaks (i.e., \\n ). I've tried using regular expressions to remove one of the backslashes before setting the value of the textarea--not working.

Here's a re-creation of the problem: http://jsfiddle.net/xkM23/3/

Does anyone know how to get the line breaks to show up properly in that textarea?

like image 404
Elliot B. Avatar asked Jan 29 '26 11:01

Elliot B.


1 Answers

You have to escape \ for JavaScript (and make them double \\). Then it's working as intended: http://jsfiddle.net/xkM23/6/

.replace(/(\\r)|(\\n)/g,"\n")
like image 195
Michał Miszczyszyn Avatar answered Jan 31 '26 03:01

Michał Miszczyszyn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!