Skip to content

Instantly share code, notes, and snippets.

@cristinaITdeveloper
Created May 15, 2017 12:32
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 cristinaITdeveloper/8fcc12820ddf2b9469df9a1b65354609 to your computer and use it in GitHub Desktop.
Save cristinaITdeveloper/8fcc12820ddf2b9469df9a1b65354609 to your computer and use it in GitHub Desktop.
Javascript replace all character in string
function escapeRegExp(str) {
return str.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
}
function replaceAll(str, find, replace) {
return str.replace(new RegExp(escapeRegExp(find), 'g'), replace);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment