Created
July 19, 2020 07:16
-
-
Save kieranbarker/17188e65499b6731801b42cc01214fe2 to your computer and use it in GitHub Desktop.
Escape double and single quotes inside a string
This file contains 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
/** | |
* Escape double and single quotes inside a string | |
* @param {String} string The string | |
* @returns {String} The string with quotes escaped | |
*/ | |
function escapeQuotes (string) { | |
return string.replace(/"/g, """).replace(/'/g, "'"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment