Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mde
Created June 9, 2014 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mde/2c4fe6906db45d652b88 to your computer and use it in GitHub Desktop.
Save mde/2c4fe6906db45d652b88 to your computer and use it in GitHub Desktop.
Escape any escape sequences in a string
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