What The Glob
I ran across the node-glob and realized I didn’t know what a glob is. I read through the node-glob documentation and found out globs are a form of pattern matching. I realized I had been using globs for a long time, like the wildcard notation, without knowing its name.
Wildcards
There are generally two wildcards you can use for glob functions.
*
- “any string of characters”?
- one character
There are also brackets, where the character must be one of the following, or given as a range.
[abc]
- one of “a”, “b”, or “c”[a-z]
- between the range of “a” to “z”.
You can also line this up with a ”!” to mean not in the following bracket.
[!abc]
- not one of “a”, “b”, or “c”[!a-z]
- not in the range of “a” to “z”
The examples above are used in UNIX-based systems. These commands are slightly different in Window’s Powershell and SQL. For more information about those systems, you can read the Wikipedia article about globs.
Node Example
var glob = require("glob");
// options is optional
glob("**/*.js", options, function (er, files) {
// files is an array of filenames.
// If the `nonull` option is set, and nothing
// was found, then files is ["**/*.js"]
// er is an error object or null.
});
Written by Jeremy Wong and published on .