Glob 模式示例

Glob 模式示例,用于文件匹配,从基本到复杂模式

📝 简单通配符模式

🟢 simple

使用 * 匹配任意字符的基本模式

🏷️ glob, pattern, wildcard, file-matching, basic
*.txt

📝 文件扩展名匹配

🟢 simple

匹配多个扩展名的文件

🏷️ glob, pattern, wildcard, file-matching, extension, basic
*.{js,ts,jsx,tsx}

📝 目录模式

🟢 simple

匹配特定目录中的文件

🏷️ glob, pattern, wildcard, file-matching, directory, basic
src/*.ts

📝 嵌套目录

🟡 intermediate

匹配嵌套目录结构中的文件

🏷️ glob, pattern, wildcard, file-matching, directory, intermediate
src/components/*.tsx

📝 递归模式(Globstar)

🟡 intermediate

使用 ** 模式递归匹配文件

🏷️ glob, pattern, wildcard, file-matching, recursive, intermediate
src/**/*.ts

📝 复杂递归模式

🟡 intermediate

带有多个通配符的深度嵌套模式

🏷️ glob, pattern, wildcard, file-matching, recursive, intermediate
**/*.{test,spec}.{js,ts}

📝 字符类模式

🟡 intermediate

使用字符类 [abc] 进行精确匹配

🏷️ glob, pattern, wildcard, file-matching, character-class, intermediate
src/[A-Z]*.ts

📝 大括号扩展

🟡 intermediate

使用 {a,b,c} 匹配多个选项

🏷️ glob, pattern, wildcard, file-matching, brace-expansion, intermediate
src/{components,utils,types}/*.ts

📝 命名组模式

🟡 intermediate

用于匹配编号/日期文件的模式

🏷️ glob, pattern, wildcard, file-matching, numbered, intermediate
logs/app-[0-9]*.log
backup-[0-9][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9].tar.gz

📝 否定模式

🔴 complex

使用 ! 前缀排除模式

🏷️ glob, pattern, wildcard, file-matching, negation, advanced
src/**/*.ts
!**/*.test.ts
!**/*.spec.ts

📝 综合项目模式

🔴 complex

用于完整项目匹配的复杂模式

🏷️ glob, pattern, wildcard, file-matching, comprehensive, advanced
src/**/*.{ts,tsx}
!**/*.test.ts
!**/*.spec.ts
!**/node_modules/**
public/**/*.html
**/*.json

📝 多个忽略模式

🔴 complex

构建工具和 gitignore 的常用模式

🏷️ glob, pattern, wildcard, file-matching, negation, advanced
**/*.ts
!**/*.d.ts
!**/node_modules/**
!**/dist/**
!**/.git/**
**/*.graphql
**/*.gql