I am trying to use javascript's replace function to replace a string. But it just replaces the first instance. So when I use regular global expressions,
var result = 'moaning|yes you|hello test|mission control|com on'.replace(/|/g, ';');
I get: http://jsfiddle.net/m8UuD/196/
I want to get:
moaning;yes you;hello test;mission control;com on
Simply escape the pipe :
'moaning|yes you|hello test|mission control|com on'.replace(/\|/g, ';');
Here you'll find the list of regex special characters that you should generally escape.
var result = 'moaning|yes you|hello test|mission control|com on'.replace(/\|/g, ';');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With