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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The code should work – with the
/gflag, it should replace all<br>s. It’s possible the problem is elsewhere.Try this:
'\n'is probably more appropriate than\r– it should be globally recognized as a newline, while\risn’t common on its own. On Firefox, for example,\risn’t rendered as a newline.