Reputation: 763
"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.
Upvotes: 3
Views: 722
Reputation: 3641
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()
Upvotes: 15
Reputation: 39512
You need to use a Regex literal, not a string:
"test<br>test<br>test<br>test".replace(/<br>/g, '\n');
Upvotes: 12