Glob Pattern Mastery — Precise File Targeting
Core 6 min +25 XP
💡
THE ANALOGY
Regular expressions for file paths. Just as regex lets you match strings with precision, glob patterns let you target files with precision — not just by name, but by location, extension, depth, and exclusion.
⚠️ EXAM TRAP — The Wrong Answer People Choose
The difference between * and ** in globs. A single * matches within one directory level. Double ** matches across any number of directory levels. 'src/*.ts' matches only TypeScript files directly in src/. 'src/**/*.ts' matches TypeScript files in src/ and all subdirectories.
KEY POINTS
1 * matches any characters within a single directory level — does not cross directory boundaries.
2 ** matches across any number of directory levels — the 'recursive' wildcard.
3 ? matches exactly one character.
4 ! at the start of a pattern means exclusion — matches everything EXCEPT this pattern.
5 Patterns are evaluated relative to the project root — use ./ prefix if needed for clarity.