"test<br>test<br>test<br>test".replace('/<br>/g', '\n');
Does not replace the <br>
's with \n
, it leaves the string unchanged. I can't figure out why.
"test<br>test<br>test<br>test".replace('/<br>/g', '\n');
Does not replace the <br>
's with \n
, it leaves the string unchanged. I can't figure out why.
-
6
'/<br>/g'
is a string, not a regex. Lose the quotes. It's looking for the literal string'/<br>/g'
. You want.replace(/<br>/g, '\n');
. JavaScript has RegEx literals. – gen_Eric Commented Apr 7, 2014 at 17:51 - 1 duplicate of stackoverflow./questions/8062399/… – Mostafa Berg Commented Apr 7, 2014 at 17:52
2 Answers
Reset to default 15Because you're passing the regex object as a string instead of a regex. Remove the ''
from the first argument you're passing to replace()
You need to use a Regex literal, not a string:
"test<br>test<br>test<br>test".replace(/<br>/g, '\n');