Skip to content

Instantly share code, notes, and snippets.

@lewisjb
Created October 24, 2016 14:19
Show Gist options
  • Save lewisjb/558d2b4ec9af7948055282d2509d9af7 to your computer and use it in GitHub Desktop.
Save lewisjb/558d2b4ec9af7948055282d2509d9af7 to your computer and use it in GitHub Desktop.
Slack /s with regex and substitution
TS.utility.msgs.wordReplace = function (text, replace_object) {
if(!replace_object){
return text;
}
var rx_opts = (replace_object.g ? "g" : "") + (replace_object.i ? "i" : "");
var rx = new RegExp(replace_object.str, rx_opts);
return text.replace(rx, replace_object.rpl.replace(/\\(\d+)/g, "$$1"));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment