Skip to content
uencoder

Glob

Glob is shell-style file-path pattern matching that uses wildcards such as * ** ? [] to match file names; it is simpler than regex.

Purpose

Provides simple pattern matching for file systems without the complex syntax of regex.

Mechanism

* matches any characters within a single path segment (excluding /); ** recursively matches multiple directory levels; ? matches a single character; [] matches a character class; {} matches optional groups. Expanded into file lists by the shell or libraries such as minimatch/picomatch. Widely used by .gitignore, npm, and Vite.

Use cases

  • .gitignore and npm ignore rules
  • Build-tool file include/exclude patterns
  • Shell commands (ls *.js)
  • IDE file filtering

Examples

  • Input
    src/**/*.ts
    Output
    All .ts files under src (recursive)

    ** recursion

Common errors

Confusing * with ** (single level vs recursive)
** must be enabled via configuration (e.g., in minimatch)

Related terms

References