Bun

interface

RegExpConstructor

interface RegExpConstructor

  • constructor RegExpConstructor(
    pattern: string | RegExp
    ): RegExp;
    constructor RegExpConstructor(
    pattern: string,
    flags?: string
    ): RegExp;
    constructor RegExpConstructor(
    pattern: string | RegExp,
    flags?: string
    ): RegExp;
  • readonly prototype: RegExp
  • string: string
    ): string;

    Escapes any potential regex syntax characters in a string, and returns a new string that can be safely used as a literal pattern for the RegExp() constructor.

    MDN Reference

    const re = new RegExp(RegExp.escape("foo.bar"));
    re.test("foo.bar"); // true
    re.test("foo!bar"); // false