Function createFilenameRegex

  • Create a simple filename style regular expression from the string value, converting any embedded filename wildcard 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 (including folder seperators ''/' or '\')
    • '?' Matches any single character once only (including folder seperators '/' or '\')
    • '/' Matches either '/' or '\' character, not captured as a group
    • '\' Matches either '/' or '\' character, not captured as a group

    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 = createFilenameRegex("*.txt");

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

    let matches = regex.exec("ug.txt");
    matches[0]; // "ug.txt"
    matches[1]; // "ug"

    let matches = regex.exec(" ug.txt ");
    matches[0]; // " ug.txt"
    matches[1]; // " ug"

    let matches = regex.exec("C:\\temp\\ug.txt");
    matches[0]; // "C:\\temp\\ug.txt"
    matches[1]; // "C:\\temp\\ug"

    let matches = regex.exec("/var/log/ug.txt");
    matches[0]; // "/var/log/ug.txt"
    matches[1]; // "/var/log/ug"