What are glob patterns?

Glob patterns are wildcard matching patterns used to specify sets of filenames or paths. They originated in Unix shells but are now used across programming languages and tools. Common wildcards include * (matches any characters), ** (matches directories recursively), ? (matches single character), and [abc] (matches any character in brackets). These patterns are essential for file operations, build tools, and version control systems like Git.

How do glob patterns work?

Glob patterns use special wildcard characters to match file paths. Here are the most common patterns:

  • * - Matches any number of characters within a single directory level
    • Example: *.js matches file.js, test.js but not folder/file.js
  • ****** - Matches any number of directories (recursive matching)
    • Example: **/*.js matches file.js, src/file.js, src/utils/file.js
  • ? - Matches exactly one character
    • Example: file?.js matches file1.js, fileA.js but not file10.js
  • [abc] - Matches any single character from the set
    • Example: file[123].js matches file1.js, file2.js, file3.js
  • [a-z] - Matches any character in the range
    • Example: [A-Z]*.js matches files starting with uppercase letters
  • {js,ts} - Matches any of the comma-separated patterns (brace expansion)
    • Example: *.{js,ts} matches file.js and file.ts
  • !pattern - Negates the pattern (excludes matching files)
    • Example: !*.test.js excludes all test files

Practical examples:

  • src/**/*.{js,ts} - All JavaScript and TypeScript files in src directory and subdirectories
  • lib/**/test/*.js - All JavaScript files in test folders within lib
  • **/*.min.js - All minified JavaScript files anywhere in the project
  • !node_modules/** - Exclude everything in node_modules directory

Tool description

An online glob tester for testing and validating glob patterns against file paths in real-time. This glob pattern checker uses the picomatch library to provide accurate pattern matching, allowing developers to quickly test their glob expressions before implementing them in configuration files, scripts, or applications. The glob syntax tester interface provides instant feedback on which paths match your pattern, helping you refine and perfect your glob expressions with this intuitive glob expression tester.

Features

  • Real-time pattern matching: Instantly see which paths match your glob pattern as you type with this online glob tester
  • Multiple path testing: Test glob patterns against multiple file paths simultaneously
  • Pattern options: Configure case sensitivity and dotfile matching behavior in the glob pattern checker
  • Visual feedback: Clear indication of matching and non-matching paths with color-coded badges
  • Tabular results: Organized display of test results in a clean, sortable table format
  • Error handling: Immediate feedback on invalid glob syntax with error messages
  • Match statistics: Summary showing the number of matches out of total paths tested

Use Cases

  • Build configuration: Test glob patterns for build tools like Webpack, Vite, or Rollup before adding to config
  • Git ignore patterns: Validate .gitignore patterns with this glob pattern tester to ensure they match the intended files
  • File processing scripts: Verify glob expressions for file selection in Node.js scripts or automation tools
  • Test file selection: Use the glob syntax tester to configure test runners (Jest, Mocha) to select correct test files
  • ESLint and Prettier: Test file patterns with this glob expression tester for linter and formatter configuration
  • Documentation: Verify glob patterns for documentation generators and file processors
  • CI/CD pipelines: Test path matching patterns for continuous integration workflows with this online glob tester
  • Learning glob syntax: Experiment with glob patterns in this glob pattern checker to understand their behavior