Binato/server/Util.ts

8 lines
362 B
TypeScript
Raw Normal View History

2022-11-16 15:25:46 +00:00
// Taken from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
function escapeRegExp(string:string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
export function replaceAll(inputString:string, toReplace:string, toReplaceWith:string) {
return inputString.replace(`/:${escapeRegExp(toReplace)}:/g`, toReplaceWith);
}