UNPKG

shoetest

Version:

Powerful string matching insensitive to diacritics, special characters, symbols and case

26 lines 909 B
"use strict"; // Regular Expression Utilities Object.defineProperty(exports, "__esModule", { value: true }); exports.escape = escape; // Characters that have special meaning in regular expressions const REGEX_SPECIAL_CHARS = /[.*+?^${}()|[\]\\]/g; /** * Safely escape special regex characters * * Converts special regex characters to their literal equivalents by adding * backslashes, making the string safe to use in regex patterns. * * @param str - Text containing potential regex special characters * @returns Escaped text safe for regex use * * @example * ```typescript * escape('Hello (world)'); // → 'Hello \\(world\\)' * escape('Price: $5.99'); // → 'Price: \\$5\\.99' * escape('.*+?^${}()|[]\\'); // → '\\.\\*\\+\\?\\^\\$\\{\\}\\(\\)\\|\\[\\]\\\\' * ``` */ function escape(str) { return str.replace(REGEX_SPECIAL_CHARS, '\\$&'); } //# sourceMappingURL=regexp.js.map