Advanced Patterns
Complex glob patterns and advanced matching techniques.
Extended Glob Syntax
Section titled “Extended Glob Syntax”Character Classes
Section titled “Character Classes”use Cline\Globby\Globby;
// Match specific characters$files = Globby::find('file[123].txt'); // file1.txt, file2.txt, file3.txt
// Match character range$files = Globby::find('file[a-z].txt'); // filea.txt through filez.txt
// Negate characters$files = Globby::find('file[!0-9].txt'); // Exclude numericBrace Expansion
Section titled “Brace Expansion”// Match alternatives$files = Globby::find('*.{js,ts,jsx,tsx}');
// Nested braces$files = Globby::find('{src,lib}/**/*.{js,ts}');
// Numeric ranges$files = Globby::find('log-{1..10}.txt');Extended Patterns
Section titled “Extended Patterns”// Zero or more directories$files = Globby::find('**/test/**/*.php');
// Exactly one directory level$files = Globby::find('src/*/index.php');
// Optional parts$files = Globby::find('**/*@(.test|.spec).js');Complex Examples
Section titled “Complex Examples”Monorepo Patterns
Section titled “Monorepo Patterns”// All package.json files$packages = Globby::find('packages/*/package.json');
// All source files in packages$sources = Globby::find('packages/*/src/**/*.{ts,tsx}');
// Tests across all packages$tests = Globby::find('packages/*/{test,tests,__tests__}/**/*.ts');Framework-Specific
Section titled “Framework-Specific”// Laravel controllers$controllers = Globby::find('app/Http/Controllers/**/*Controller.php');
// React components$components = Globby::find('src/components/**/*.{jsx,tsx}');
// Config files$configs = Globby::find('{config,conf}/**/*.{json,yaml,yml,toml}');Exclusion Patterns
Section titled “Exclusion Patterns”// All PHP except tests$files = Globby::find('**/*.php', exclude: [ '**/*Test.php', '**/*TestCase.php', 'tests/**',]);
// Source without generated files$files = Globby::find('src/**/*', exclude: [ '**/*.generated.*', '**/dist/**', '**/.cache/**',]);Performance Tips
Section titled “Performance Tips”// More specific patterns are fasterGlobby::find('src/**/*.php'); // BetterGlobby::find('**/*.php'); // Slower (searches everywhere)
// Use exclusions wiselyGlobby::find('**/*', exclude: ['vendor/**', 'node_modules/**']);
// Limit depth when possibleGlobby::find('*/*.php'); // Only one level deepGlobby::find('**/*.php', depth: 3); // Max 3 levelsRegular Expression Matching
Section titled “Regular Expression Matching”// When glob isn't enough, use regex$files = Globby::findByRegex('#/[A-Z][a-z]+Controller\.php$#');
// Combine glob and regex$files = Globby::find('src/**/*.php') ->filter(fn($f) => preg_match('/^[A-Z]/', $f->getFilename()));