Skip to content

The ** wildcard ​

** is the only wildcard that crosses /. This page explains when ** counts as a real "any depth" wildcard, what it matches at the start, middle, and end of a pattern, and how it behaves next to braces. For the rest of the syntax, see Pattern syntax.

All examples use the default options (dot: true, caseInsensitive: false) unless a table says otherwise.

What ** matches ​

A real ** matches zero or more whole path segments. Zero segments count: src/**/*.ts matches src/index.ts, where ** matches nothing. On its own, ** matches any path, even the empty one.

PatternPathMatch?
src/**/*.tssrc/index.tsyes
src/**/*.tssrc/a/b/c.tsyes
src/**/*.tslib/a.tsno
src/**/test/*.tssrc/test/a.tsyes
src/**/test/*.tssrc/a/b/test/c.tsyes
src/**/test/*.tssrc/test/a/b.tsno
**.github/workflows/ci.ymlyes

The last src/**/test/*.ts row fails because * after test/ still matches only one segment.

Spec: GLOB_SPEC §9.2

** must own a whole segment ​

** is a real "any depth" wildcard only when it fills a whole segment:

  • before it comes a / or the start of the pattern, and
  • after it comes a / or the end of the pattern.

Anywhere else, ** is just two * in a row, and that means the same as one *. It stays inside one segment.

PatternMeans the same asReal **?
src/**/*.ts—yes
**/*.ts—yes
src/**—yes
**—yes
src/**.tssrc/*.tsno
**.js*.jsno
src**/xsrc*/xno
a**ba*bno
PatternPathMatch?
src/**.tssrc/a.tsyes
src/**.tssrc/a/b.tsno
**.jsa.jsyes
**.jslib/a.jsno
a**baxbyes
a**ba/bno

**.js is not every .js file

A ** joined to other characters is a plain *. To match .js files at any depth, write **/*.js.

Spec: GLOB_SPEC §9.1

A trailing /** and the directory itself ​

dist/** means "dist/ followed by anything". The dist/ part is required, so the bare path dist does not match. The path dist/ does match: ** matches the empty rest.

PatternPathMatch?
dist/**distno
dist/**dist/yes
dist/**dist/app.jsyes
dist/**dist/assets/logo.svgyes
{dist,dist/**}distyes
{dist,dist/**}dist/assets/logo.svgyes

To match the directory and everything in it, list both, as in {dist,dist/**}. When a file walker asks "should I enter this directory?", it uses matchDir instead of match; see Directory matching.

Spec: GLOB_SPEC §9.3

A leading **/ means "at any depth" ​

A pattern that starts with **/ matches the rest at any depth, including depth zero. It also accepts absolute paths, UNC paths, and Windows drive paths, so **/*.rs really means "every .rs file".

PatternPathMatch?
**/node_modulesnode_modulesyes
**/node_modulespackages/web/node_modulesyes
**/node_modules/home/me/app/node_modulesyes
**/node_modules//server/share/node_modulesyes
**/node_modulesC:/proj/node_modulesyes
**/node_modulesnode_modules/reactno
**/node_modules/**node_modules/react/index.jsyes

The node_modules/react row fails because the whole path must match. Add /** to also match what is inside.

To match only absolute paths, start the pattern with /:

PatternPathMatch?
/**/*.rssrc/main.rsno
/**/*.rs/src/main.rsyes
**/*.rs/src/main.rsyes

When a pattern starts with a brace, each branch decides this by itself. In {**/package.json,README.md}, the first branch accepts absolute paths and the second, a plain literal, does not:

PatternPathMatch?
{**/package.json,README.md}/repo/package.jsonyes
{**/package.json,README.md}README.mdyes
{**/package.json,README.md}/README.mdno

Spec: GLOB_SPEC §9.4

Separators around ** ​

Normally each / in a pattern matches exactly one separator. A / next to a real ** is more relaxed: it also accepts a run of separators, so src/**/index.ts matches src//index.ts.

PatternPathMatch?
src/**/index.tssrc//index.tsyes
src/index.tssrc//index.tsno

Spec: GLOB_SPEC §9.5

Repeated **/**/ ​

Two or more **/ in a row mean the same as one. **/**/*.ts is **/*.ts, and a/**/**/b is a/**/b.

PatternPathMatch?
**/**/*.tsa.tsyes
**/**/*.tssrc/a/b.tsyes
a/**/**/ba/byes
a/**/**/ba/x/y/byes

Spec: GLOB_SPEC §9.6

** and dot files ​

With dot: false, ** does not step into names that start with ., and neither do the wildcards after it. See How a path is matched.

PatternPathdot: truedot: false
**.envyesno
src/**src/.envyesno
**/*a/.byesno
**/*a/byesyes

Spec: GLOB_SPEC §12

** and braces ​

A brace branch may contain its own **; each branch is a pattern of its own (see Braces and **). What needs care is a ** at the edge of a brace.

** next to a brace ​

A brace means "any one of these branches" (see Brace expansion). To check whether a ** next to a brace owns a segment, write out each choice as a separate pattern and apply the normal rule to each one. The same ** can be a real ** in one choice and a plain * in another.

PatternWrite out each choiceResult
{**,dist}/*.js**/*.js or dist/*.jsreal ** in the first
src{**,x}.tssrc**.ts or srcx.ts** acts as *
**{/a,b}**/a or **breal **, then *
{a/,b}**a/** or b**real **, then *
{a/**,x}ca/**c or xc** acts as *
PatternPathMatch?
{**,dist}/*.jsa/b/c.jsyes
{**,dist}/*.jsdist/a.jsyes
src{**,x}.tssrcfoo.tsyes
src{**,x}.tssrc/a.tsno
**{/a,b}x/y/ayes
**{/a,b}xbyes
**{/a,b}x/bno
{a/,b}**a/x/yyes
{a/,b}**b/xno
{a/**,x}ca/z/cno

Spec: GLOB_SPEC §10.1, §9.1

** inside a brace with no comma ​

A brace with no comma is not a brace: {**} is the plain characters {, **, }. Here ** sits between { and }, so it acts as *. A ** with / on both sides is still real, even inside such literal braces.

PatternPathMatch?
{**}{a}yes
{**}{a/b}no
{a/**/b}{a/x/y/b}yes

Spec: GLOB_SPEC §10.4

Released under the MIT License.