glob minimatch picomatch nodejs web-development patterns

Guia de Padrões Glob para Web: Glob, Minimatch e Picomatch

Domine padrões glob para desenvolvimento web. Um guia abrangente da sintaxe Glob, Minimatch e Picomatch. Inclui exemplos comuns, uma folha de dicas de sintaxe e recomendações de testadores glob online.

2026-04-11

Web Matching Glob Patterns Guide: Master Your File Selections

In modern web development, selecting specific files or directories from a large codebase is a frequent task. Whether you are configuring a build tool like Webpack, setting up a linting rule with ESLint, or defining a search pattern in your Node.js script, you are likely using glob patterns.

This guide covers the essentials of glob matching, focusing on the most popular libraries: Glob, Minimatch, and Picomatch. We will dive into the syntax, provide a cheat sheet, and explain why using a tester online or playground is essential for mastering these patterns.


1. What are Glob Patterns?

Glob patterns (or globs) are strings of characters used to match file and directory names. Unlike regular expressions, which are designed for searching within strings, globs are optimized for filesystem paths. They are simpler than regex but incredibly powerful for file-matching tasks.

Most JavaScript-based tools use libraries like minimatch, micromatch, or picomatch under the hood to handle these patterns.


2. The Core Syntax of Glob Patterns

Understanding the basic characters is the first step to mastering glob patterns.

  • * (Asterisk): Matches any number of characters within a single directory level.
    • Example: src/*.js matches src/app.js but not src/utils/math.js.
  • ** (Globstar): Matches any number of characters across multiple directory levels.
    • Example: src/**/*.js matches src/app.js, src/utils/math.js, and src/components/button/index.js.
  • ? (Question Mark): Matches exactly one character.
    • Example: test/file?.js matches test/file1.js but not test/file10.js.
  • [ ] (Character Class): Matches any one character within the brackets.
    • Example: config/[abc].json matches config/a.json, config/b.json, or config/c.json.
  • { } (Brace Expansion): Matches a comma-separated list of patterns.
    • Example: src/**/*.{js,ts} matches all .js and .ts files recursively.
  • ! (Negation): Excludes files that match the following pattern.
    • Example: src/**/*.js combined with !src/**/*.test.js selects all JS files except tests.

3. Minimatch vs. Picomatch vs. Glob

While the basic syntax is largely shared, there are subtle differences between the popular libraries:

Glob (Node-glob)

The original and most widely used globbing library for Node.js. It performs the actual file system traversal.

  • Strength: Handles the file system interaction directly.

Minimatch

The glob matcher used by npm itself. It is a simple string matcher that doesn't interact with the filesystem.

  • Strength: Reliable, battle-tested, and used in millions of projects.

Picomatch

A newer, faster, and more lightweight alternative to Minimatch. It is often used inside micromatch.

  • Strength: High performance and strict adherence to POSIX standards.

4. Common Glob Pattern Examples

Goal Pattern
All JS files in root *.js
All JS files in src src/*.js
All files in dist recursively dist/**/*
All images (png, jpg, webp) images/**/*.{png,jpg,webp}
Everything except node_modules !(node_modules)/**/*
Match file1.js to file9.js file[1-9].js

5. Why Use a Glob Tester Online or Playground?

Glob patterns can be tricky, especially when nesting braces and double asterisks. Using a tester online or playground is the best way to ensure your patterns work as expected.

  1. Visual Verification: A tester online shows you a list of sample files and highlights exactly which ones match your pattern in real-time.
  2. Syntax Highlighting: Many playgrounds provide syntax highlighting for globs, making it easier to spot unmatched braces or misplaced asterisks.
  3. Library Switching: Some testers allow you to switch between Minimatch, Picomatch, and Glob engines to see if there are any differences in behavior.
  4. Learning Environment: A playground is a safe place to experiment with complex negations and expansions without accidentally deleting files on your local machine.
  5. Debug Shared Configs: If your .gitignore or .eslintignore isn't working, you can paste the patterns into a tester online to verify the logic.

6. Frequently Asked Questions (FAQ)

Q: What is the difference between * and **?

A: * only matches within one directory. ** (the globstar) matches recursively through any number of subdirectories.

Q: Why isn't my glob pattern matching hidden files?

A: Most glob libraries exclude files starting with a dot (like .env) by default. You often need to enable a dot: true option or use a pattern like **/.* to include them.

Q: Is glob syntax the same as RegEx?

A: No. While they share some symbols (like *), the meaning is different. In regex, * means "zero or more of the previous character," while in globs, it means "any characters in a path segment."


7. Related Tools

Need a reliable tester online for your glob patterns? We are building a high-performance Glob Playground at Tool3M that supports multiple engines including Picomatch and Minimatch.

In the meantime, if you're working with complex data IDs, check out our UUID Generator to generate unique identifiers for your test files.