"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.
Because 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');
/g'` is a string, not a regex. Lose the quotes. It's looking for the *literal* string `'/
/g'`. You want `.replace(/
/g, '\n');`. JavaScript has RegEx literals. – gen_Eric Apr 07 '14 at 17:51