Pattern: File mask

“File mask” is one of the patterns that you can select on the Match panel. With this pattern you can convert a traditional file mask or globbing expression into a regular expression. The converted regex can stand on its own (if the file mask is the only field on the Match panel) or be part of a larger regular expression.

File Masks

Enter one or more file masks that match the file names, folder names, or paths that this field should match. File masks are also known as globbing expressions. They are different from regular expressions. They support the wildcard * which matches any number of any character and the wildcard ? which matches any single character. They also support character sets using square brackets. These match one character from a set of characters. A hyphen inside a character class forms a range. [aeiou0-9] matches any vowel or any digit. A character set can be negated by starting it with a caret or exclamation point. [!aeiou0-9] and [^aeiou0-9] both match any single character that is not a vowel or a digit.

There is no mechanism for escaping metacharacters. This is not needed because the characters * and ? are not allowed in file and folder names. In character sets, metacharacters can be included as literal characters by placing them where they do not have their special meaning. The closing bracket does not have a special meaning if it is the first character in the set (after the negating caret or exclamation point, if any) because empty sets are not allowed. The hyphen does not have a special meaning when it is the first or last character in the set. The caret and exclamation point only have a special meaning immediately after the opening bracket. So [][!^-] matches a literal square bracket, exclamation point, caret, or hyphen.

You can specify multiple file masks by delimiting them with commas, semicolons, or line breaks. To include literal commas or semicolons in a file mask, enclose the entire file mask with double quotes. The file mask "1,2,3.txt",123.txt matches the two file names 1,2,3.txt and 123.txt. Alternatively, you can place commas and semicolons inside character classes to treat them as literals. 1[,]2[,]3.txt,123.txt is functionally identical to the previous file mask.

Normally, file masks or globbing expressions need to match the entire file name. The mask file[0-9].txt matches file0.txt to file9.txt but normally does not match another file0.txt. RegexMagic does not enforce this. This allows you to use the file mask file[0-9].txt to generate a regex that finds file0.txt to file9.txt in the contents of a larger document. If you want the generated regex to match the subject string entirely like an actual file mask would then set begin regex match at and end regex match at to the start and end of the subject string.

Examples