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

    Function makeGlobRegex

    • Create a simple glob style regular expression from the string value, converting '**', '*' and '?' characters. Unlike createFilenameRegex the '*' and '?' will NOT match folder seperator characters '/' and '\'. If the source string contains folder seperators both '/' and '\' are treated as synonomous Each wildcard match will be captured as it's own group. The supported matching values are

      • '**' Matches any characters zero or more times include folder seperators '/' or '\'
      • '*' Matches any characters zero or more times, except '/' or '\'
      • '?' Matches any single character once only, except '/' or '\'
      • '/' Matches either '/' or '\' character, not captured as a group
      • '\' Matches either '/' or '\' character, not captured as a group

      Since v0.20.0 a '**' which is followed by a folder separator matches the folders with one group which can only match a path in one way, so a path which doesn't match no longer takes exponential time (eg. matching all the .txt files against 61 characters of repeated "a/" took ~10s). As for createWildcardRegex, each other wildcard ('**' and '*') can still backtrack, so the time to fail grows with the length of the string to the power of the number of these wildcards (and an unanchored expression, without fullMatch, also tries each starting position), so limit the length of an untrusted string before matching it.

      Parameters

      • value: string

        The string value to converted.

      • OptionalignoreCase: boolean

        Flag to indicate whether the regular expression should be case-sensitive, Defaults to false.

      • OptionalfullMatch: boolean

        Flag to identify whether the RegExp should be wrapped with '^' and '$' to incidate match the entire string only.

      Returns RegExp

      The new Regular Expression created from the provided value.

      0.9.0

      let regex = makeGlobRegex("src\\**\\*.ts");

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

      let matches = regex.exec("Src/index.ts");
      matches; // null - Specify the ignoreCase if you want this to match

      let matches = regex.exec("src/index.ts");
      matches[0]; // "src/index.ts"
      matches[1]; // undefined;
      matches[2]; // "index"

      let matches = regex.exec("src\\index.ts");
      matches[0]; // "src\\index.ts"
      matches[1]; // undefined;
      matches[2]; // "index"

      let matches = regex.exec("src/helpers/regexp.ts");
      matches[0]; // "src/helpers/regexp.ts"
      matches[1]; // "helpers/"
      matches[2]; // "regexp"

      let matches = regex.exec("src\\helpers/regexp.ts");
      matches[0]; // "src\\helpers/regexp.ts"
      matches[1]; // "helpers/"
      matches[2]; // "regexp"

      let matches = regex.exec(" src/index.tsx ");
      matches[0]; // "src/index.ts"
      matches[1]; // undefined
      matches[2]; // "index"

      let matches = regex.exec(" src/helpers/regexp.ts. ");
      matches[0]; // "src/helpers/regexp.ts"
      matches[1]; // "helpers/"
      matches[2]; // "regexp"]);