I have a string
var str= 'asdf<br>dfsdfs<br>dsfsdf<br>fsfs<br>dfsdf<br>fsdf';
I want to replace <br> with \r by using
str.replace(/<br>/g,'\r');
, but it is replacing only the first <br>... Any idea why?
The code should work - with the /g flag, it should replace all <br>s. It's possible the problem is elsewhere.
Try this:
str = str.replace(/<br>/g, '\n');
'\n' is probably more appropriate than \r - it should be globally recognized as a newline, while \r isn't common on its own. On Firefox, for example, \r isn't rendered as a newline.
replace(/<br>/g,'\r')replaces all<br>here ... Or did you only want to replace the first<br>?