MCPcopy Create free account
hub / github.com/Snapchat/Valdi / escapeRegexSpecialChars

Function escapeRegexSpecialChars

valdi/vscode_debugger/src/common/stringUtils.ts:42–51  ·  view source on GitHub ↗
(str: string, except?: string)

Source from the content-addressed store, hash-verified

40export const isRegexSpecialChar = (chr: string) => regexChars.includes(chr);
41
42export 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}

Callers 5

replacePathMethod · 0.90
constructorMethod · 0.90
createTargetFilterFunction · 0.90
_updateBlackboxedUrlsMethod · 0.90

Calls 5

filterMethod · 0.80
splitMethod · 0.80
replaceMethod · 0.65
joinMethod · 0.45
indexOfMethod · 0.45

Tested by

no test coverage detected