Skip to content

Instantly share code, notes, and snippets.

@adorr
Created February 6, 2012 17:08
Show Gist options
  • Save adorr/1753375 to your computer and use it in GitHub Desktop.
Save adorr/1753375 to your computer and use it in GitHub Desktop.
regex = /foo/;
//regex = /foo/g;
"foobarfoobar".replace(regex, function(str) {
if (RegExp.rightContext == "") {
return "ninja";
} else {
return "pirate";
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment