Replace not replacing all occurrences javascript

Hey,

I did this:

var message = String(json.message).replace(‘/<br \/\>/g’, ‘’);

and it’s not replacing any of the <br /> found. I did do this:

var message = String(json.message).replace(‘<br \/\>’, ‘’);

And it replaced one of occurrences but not all of them.

Anyone know what’s going on?

Your replace expression is a string, and it is not finding any ‘’/<br \/\>/g"
Lose the quotes to create a regular expression.

You could also make it work in html as well as xhtml,
by making it case-insensitive and optionally self closing-

var message = String(json.message).replace(/<br *(\/)?>/gi, ‘’);