Escapes the RegExp special characters in string.

Info

Useful when dynamically creating regex from user input.

Syntax

TypeScript
import { escapeRegExp } from "@opentf/std";

escapeRegExp(str: string)

Examples

TypeScript
const search = "[opentf]";
const regex = new RegExp(escapeRegExp(search));

regex.test("[opentf]"); //=> true
Last updated on
Edit this page