Replacement of a substring with itself¶
Replacing a substring with itself has no effect and usually indicates a mistake, such as misspelling a backslash escape.
Examine the string replacement to find and correct any typos.
The following code snippet attempts to backslash-escape all double quotes in
raw by replacing all instances of
var escaped = raw.replace(/"/g, '\"');
However, the replacement string
'\"' is actually the same as
\" interpreted as an identity escape, so the replacement does nothing. Instead, the replacement string should be
var escaped = raw.replace(/"/g, '\\"');