I am trying to find and replace line breaks in text using javascript.
The following works. It replaces the character a with the character z.
var text = "aasdfasdf";
text= text.replace(/a/g,"z");
alert(text);
The following based on other posts on this and other message boards does not. Basically the javascript does not fire:
var text = "aasdfasdf";
text= text.replace(/\n/g,"z");
alert(text);
...Here is one of many posts that suggests it should work.
JavaScript: How to add line breaks to an HTML textarea?
and by the way following does not work for me in Firefox either:
text = text.replace(/\n\r?/g, '<br />'); or
text = text.replace("\n", '<br />');
Note: I realize there are no line breaks in the text variable..I am just using a simple string for testing purposes.
Can anyone see what could be wrong or show me a way to do this that actually works.
Thanks.
tags?](https://stackoverflow.com/questions/784539/how-do-i-replace-all-line-breaks-in-a-string-with-br-tags) – Jun Oct 26 '18 at 00:30