@nevware21/ts-utils
    Preparing search index...

    Function createLiteralRegex

    • Create a regular expression that escapes all special regex characters in the input string, treating it as a literal string to match.

      Parameters

      • matcher: string

        The string value to be escaped and converted into a RegExp for literal matching.

      Returns RegExp

      A new Regular Expression that matches the literal string value.

      0.14.0

      let regex = createLiteralRegex("Hello.World");

      let matches = regex.exec("Hello.World");
      matches[0]; // "Hello.World"

      let matches = regex.exec("HelloXWorld");
      matches; // null - dot does not match as wildcard

      let regex = createLiteralRegex("(test)");
      let matches = regex.exec("(test)");
      matches[0]; // "(test)"

      let matches = regex.exec("test");
      matches; // null