Glob
Glob 是 shell 风格的文件路径模式匹配,用 * ** ? [] 等通配符匹配文件名,比正则简单。
用途
提供面向文件系统的简单模式匹配,无需正则的复杂语法。
机制
* 匹配单层任意字符(不含 /),** 递归匹配多层目录,? 匹配单字符,[] 匹配字符类,{} 匹配可选组。由 shell 或 minimatch/picomatch 等库展开为文件列表。.gitignore、npm、Vite 等广泛使用。
用例
- .gitignore 与 npm ignore 规则
- 构建工具文件包含/排除
- shell 命令(ls *.js)
- IDE 文件过滤
示例
- 输入
src/**/*.ts输出All .ts files under src (recursive)** recursion
常见错误
- Confusing * with ** (single level vs recursive)
- ** must be enabled via configuration (e.g., in minimatch)