Files
suaveplan/packages/localization/i18n/i18n-icu-parser/src/interpolation/escape-regex.ts
2026-05-27 23:47:53 +01:00

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, "\\$&");
}