UNPKG

rc-js-util

Version:

A collection of TS and C++ utilities to help writing performant and correct applications, achieved through strict typing and (removable) invariant checking.

14 lines 367 B
/** * @public * Escapes RegExp special characters in strings. * * @returns The escaped string. * * @remarks * See {@link regexEscapeRegex}. */ export function regexEscapeRegex(value: string): string { // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping return value.replace(/[.*+\-?^${}()|[\]\\]/g, `\\$&`); }