Files
Foundry-VTT-Docker/resources/app/common/primitives/regexp.mjs
2025-01-04 00:34:03 +01:00

14 lines
471 B
JavaScript

/**
* Escape a given input string, prefacing special characters with backslashes for use in a regular expression
* @param {string} string The un-escaped input string
* @returns {string} The escaped string, suitable for use in regular expression
*/
export function escape(string) {
return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
}
// Define properties on the RegExp environment
Object.defineProperties(RegExp, {
escape: {value: escape}
});