Debian Codegraph @

docs/content/en/quick-reference/glob-patterns.md

raw
1 ---
2 title: Glob patterns
3 description: A quick reference guide to glob pattern syntax and matching rules for wildcards, character sets, and delimiters, featuring illustrative examples.
4 categories: []
5 keywords: []
6 ---
7
8 {{% glossary-term "glob pattern" %}}
9
10 The table below details the supported glob pattern syntax and its matching behavior. Each example illustrates a specific match type, the pattern used, and the expected boolean result when evaluated against a test string.
11
12 | Match type | Glob pattern | Test string | Match? |
13 | :--- | :--- | :--- | :--- |
14 | Simple wildcard | `images/*.jpg` | `images/a.jpg` | true |
15 | Literal match | `images/a\*.jpg` | `images/a*.jpg` | true |
16 | Single-level wildcard | `images/*/a.jpg` | `images/foo/a.jpg` | true |
17 | Single-level wildcard | `images/*/a.jpg` | `images/foo/bar/a.jpg` | false |
18 | Multi-level wildcard | `images/**/a.jpg` | `images/foo/bar/a.jpg` | true |
19 | Multi-level wildcard | `images/**/a.jpg` | `images/a.jpg` | false |
20 | Single character | `image.???` | `image.jpg` | true |
21 | Single character | `image.???` | `image.avif` | false |
22 | Delimiter exclusion | `?at` | `f/at` | false |
23 | Character list | `images/a.[jp]pg` | `images/a.jpg` | true |
24 | Negated list | `images/a.[!p]pg` | `images/a.jpg` | true |
25 | Character range | `images/a-[a-c].jpg` | `images/a-b.jpg` | true |
26 | Character range | `images/a-[a-c].jpg` | `images/a-z.jpg` | false |
27 | Negated range | `images/a-[!a-c].jpg` | `images/a-z.jpg` | true |
28 | Pattern alternates | `images/*.{jpg,png}` | `images/logo.png` | true |
29 | No match | `images/*.{jpg,png}` | `images/logo.webp` | false |
30
31 The matching logic follows these rules:
32
33 - Standard wildcard (`*`) matches any character except for a delimiter.
34 - Super wildcard (`**`) matches any character including delimiters, but when placed between two delimiters it requires at least one intervening character; it does not match zero directories.
35 - Single character (`?`) matches exactly one character, excluding delimiters.
36 - Negation (`!`) matches any character except those specified in a list or range when used inside brackets.
37 - Character ranges (`[a-z]`) match any single character within the specified range.
38
39 The delimiter is a slash (`/`), except when matching semantic version strings, where the delimiter is a dot (`.`).