Glob and .gitignore tester
Test glob patterns and .gitignore rules against a list of paths and see which paths match and which rule matched them.
Code examples
Copy and paste these into your own project. Each one uses only the language's standard library, so there is nothing to install.
const pattern = '*.log'
const names = ['app.log', 'readme.md', 'error.log']
// * stays inside one path segment, ? is one character, everything else is literal.
const source = pattern.replace(/[.+^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '[^/]*').replace(/\?/g, '[^/]')
const matcher = new RegExp(`^${source}$`)
for (const name of names.filter((candidate) => matcher.test(candidate))) {
console.log(name)
}What it does
Tests glob patterns and .gitignore rules against a list of paths. Each path is marked as matching or not, with the pattern responsible next to it, so you can see why src/lib/util.test.ts is in or out.
How to use it
- Paste one path per line, or drop a text file, into Paths.
- Write one pattern per line in Patterns. Lines that start with
#are comments. - Pick Glob, Bash or Gitignore, and show all paths, only the matches or only the misses.
- Copy the result.
Examples
With the patterns src/**/*.ts and !**/*.test.ts, the path src/lib/util.ts matches and src/lib/util.test.ts does not, because the exclusion wins. With the .gitignore rules *.log and !keep.log, app.log is ignored and keep.log is not.
Good to know
*stays inside one directory,**crosses directories, and?,[ab]and{a,b}work as in picomatch.- Dotfiles such as
.envonly match when you turn on Match dotfiles or the pattern names the dot. - In Glob and Bash a pattern that starts with
!excludes what the other patterns matched. In Gitignore the last matching rule wins, as in Git. - Bash reads
**as a plain*, like a shell withoutglobstar. - Paths are matched as text. Nothing is read from a disk.
What do the three syntaxes mean?
Glob is the picomatch syntax most build tools use: * stays inside one directory, ** crosses directories, and braces like {a,b}, classes like [ab] and ? work too. Bash reads ** as a plain *, as a shell does without globstar. Gitignore follows .gitignore rules: a trailing / means a directory, a leading / anchors to the root, and a later ! rule re-includes what an earlier rule ignored.
Frequently asked questions
Which rule is shown next to a path?
The first pattern that matched it. In glob and bash, a path that an exclusion (a pattern starting with !) removes shows that exclusion. In gitignore, the rule that ignored it is shown.
Why does * not match a file that starts with a dot?
Globs skip dotfiles unless the pattern names the dot. Turn on Match dotfiles to let * and ? match them, like bash dotglob. A .gitignore has no such switch.
Does this tool send my paths anywhere?
No. Everything happens in your browser. What you type is never sent to our servers.