Created
June 9, 2014 01:52
-
-
Save mde/2c4fe6906db45d652b88 to your computer and use it in GitHub Desktop.
Escape any escape sequences in a string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var escapeEscapeSequences = function (str) { | |
return str | |
.replace(/[\\]/g, '\\\\') // Slash has to go first | |
.replace(/[\b]/g, '\\b') | |
.replace(/[\f]/g, '\\f') | |
.replace(/[\n]/g, '\\n') | |
.replace(/[\r]/g, '\\r') | |
.replace(/[\t]/g, '\\t'); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment