11 lines
436 B
TypeScript
11 lines
436 B
TypeScript
/**
|
|
* Escape all regex metacharacters in a string so it can be used literally
|
|
* inside a RegExp constructor. Used internally by the interpolation
|
|
* engine to compile placeholder patterns from caller-supplied delimiters,
|
|
* and exported as a standalone helper for consumers building their own
|
|
* delimiter-aware patterns.
|
|
*/
|
|
export function escapeRegex(str: string): string {
|
|
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
}
|