You have to use the g
modifier (for global) in 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.
More Related Contents:
- How to replace all occurrences of a string in JavaScript
- How do I replace a character at a particular index in JavaScript?
- Fastest method to replace all instances of a character in a string [duplicate]
- How to replace all dots in a string using JavaScript
- Replace multiple strings at once
- How to replace all occurrences of a string in JavaScript
- Using jQuery to replace one tag with another
- How can I remove a character from a string using JavaScript?
- RegEx for match/replacing JavaScript comments (both multiline and inline)
- Replace a Regex capture group with uppercase in Javascript
- JavaScript .replace only replaces first Match [duplicate]
- How can I replace a regex substring match in Javascript?
- Case insensitive string replacement in JavaScript?
- Stop cursor from jumping to end of input field in javascript replace
- How do I replace all occurrences of a string in JavaScript?
- Javascript and backslashes replace
- JavaScript replace/regex
- Efficient Javascript String Replacement
- how to clear or replace a cached image
- Insert space before capital letters
- Replace a string in a file with nodejs
- JavaScript – Replace all commas in a string [duplicate]
- Why can’t I use accented characters next to a word boundary?
- Reformat string containing date with Javascript
- JavaScript replace \n with [duplicate]
- `string.replace` doesn’t change the variable [duplicate]
- Replace spaces with dashes and make all letters lower-case
- How to replace curly quotation marks in a string using Javascript?
- Javascript – Replacing the escape character in a string literal
- javascript replace globally with array