For some reason the "".replace() method only replaces the first occurrence and not the others. Any ideas?
+3
A:
You have to use the g modifier (for global) on your replace call.
str = str.replace(/searchString/g,”replaceWith”)
In your particular case it would be:
str = str.replace (/\//g, "_");
Note that you must escape the / in the regular expression.
Mayra
2010-01-29 01:11:49
You may also need the "m" option for a multiline string.
Eric Wendelin
2010-01-29 01:15:29
To make it more clear for the given problem: `str = str.replace (/\//g, "_");`
trinithis
2010-01-29 01:16:40
Thanks guys! Life saver!
illuminatedtiger
2010-01-29 01:21:24
Once your problem is solved, you should mark it as answered :)
Mayra
2010-01-29 01:35:53
+1
A:
"Your/string".split("/").join("_")
if you don't require the power of RegExp
meouw
2010-01-29 11:41:36