(str: string, except?: string)
| 40 | export const isRegexSpecialChar = (chr: string) => regexChars.includes(chr); |
| 41 | |
| 42 | export function escapeRegexSpecialChars(str: string, except?: string): string { |
| 43 | const useRegexChars = regexChars |
| 44 | .split('') |
| 45 | .filter(c => !except || except.indexOf(c) < 0) |
| 46 | .join('') |
| 47 | .replace(/[\\\]]/g, '\\$&'); |
| 48 | |
| 49 | const r = new RegExp(`[${useRegexChars}]`, 'g'); |
| 50 | return str.replace(r, '\\$&'); |
| 51 | } |
no test coverage detected