I am having a string
var countries = india*australia*pakistan*...
var replace = countries.replace("*",",");
then it will give the string as
replace = india,australia*pakistan*...
I want to replace all * with , .how can i do that with jquery or javascript
Like this:
JavaScript’s
String#replacefunction can accept either a string or a regular expression for the first argument. If it’s a string, the replacement only happens for the first match. If it’s a regular expression, it’ll be the first match or all of them if you specify thegflag (global).The regular expression is
\*, which means “match a literal*” (you need the backslash because otherwise*is special to the regular expression).