Skip to content

Instantly share code, notes, and snippets.

@JavaScript-Packer
Created May 4, 2015 00:54
Show Gist options
  • Save JavaScript-Packer/7c03f918a01ac42f1554 to your computer and use it in GitHub Desktop.
Save JavaScript-Packer/7c03f918a01ac42f1554 to your computer and use it in GitHub Desktop.
Function to replace global using regex/regexp. Live demo on http://jsfiddle.net/v6f4nbhL/
function replacer(W, H, A, K) {
K = W.replace(new RegExp(H, "g"), A);
return K;
}
var str = "WHom";
var find = "Ho";
var r3plac3 = "HAK\u002eco";
alert(replacer(str, find, r3plac3));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment