Got stumped by this for ages and all the answers kept insisting that the source string needs to already have escaped backslashes in it … which isn’t always the case.
Do this ..
var replaced = str.replace(String.fromCharCode(92),String.fromCharCode(92,92));
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 can I use backslashes (\) in a string?
- 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
- Escaping Strings 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]
- Escaping backslash in string – javascript
- 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 replace/regex
- Efficient Javascript String Replacement
- how to clear or replace a cached image
- 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]
- How do I replace all occurrences of “/” in a string with “_” in JavaScript?
- Javascript – Replacing the escape character in a string literal
- javascript replace globally with array