Open tomzx opened 9 years ago
"Globs" are the patterns you type when you do stuff like ls *.js
on
the command line, or put build/*
in a .gitignore
file.
Before parsing the path part patterns, braced sections are expanded
into a set. Braced sections start with {
and end with }
, with any
number of comma-delimited sections within. Braced sections may contain
slash characters, so a{/b/c,bcd}
would expand into a/b/c
and abc
.
The following characters have special magic meaning when used in a path portion:
*
Matches 0 or more characters in a sinle path portion?
Matches 1 character[...]
Matches a range of characters, similar to a RegExp range.
If the first character of the range is !
or ^
then it matches
any character not in the range.!(pattern|pattern|pattern)
Matches anything that does not match
any of the patterns provided.?(pattern|pattern|pattern)
Matches zero or one occurrence of the
patterns provided.+(pattern|pattern|pattern)
Matches one or more occurrences of the
patterns provided.*(a|b|c)
Matches zero or more occurrences of the patterns provided@(pattern|pat*|pat?erN)
Matches exactly one of the patterns
provided**
If a "globstar" is alone in a path portion, then it matches
zero or more directories and subdirectories searching for matches.
It does not crawl symlinked directories.If a file or directory path portion has a .
as the first character,
then it will not match any glob pattern unless that pattern's
corresponding path part also has a .
as its first character.
For example, the pattern a/.*/c
would match the file at a/.b/c
.
However the pattern a/*/c
would not, because *
does not start with
a dot character.
You can make glob treat dots as normal characters by setting
dot:true
in the options.
If you set matchBase:true
in the options, and the pattern has no
slashes in it, then it will seek for any file anywhere in the tree
with a matching basename. For example, *.js
would match
test/simple/basic.js
.
The intent for negation would be for a pattern starting with !
to
match everything that doesn't match the supplied pattern. However,
the implementation is weird, and for the time being, this should be
avoided. The behavior will change or be deprecated in version 5.
If no matching files are found, then an empty array is returned. This differs from the shell, where the pattern itself is returned. For example:
$ echo a*s*d*f
a*s*d*f
To get the bash-style behavior, set the nonull:true
in the options.
man sh
man bash
(Search for "Pattern Matching")man 3 fnmatch
man 5 gitignore
Source: https://github.com/isaacs/node-glob/blob/master/README.md
Specifically:
Extension
See https://en.wikipedia.org/wiki/Glob_(programming)