From 94b90c6282e811fc669b0adcb176956f0b75ce88 Mon Sep 17 00:00:00 2001 From: JV <43261908+jaiveer-chadda@users.noreply.github.com> Date: Sat, 24 Jan 2026 17:39:49 +0000 Subject: [PATCH] Refactored Cheatsheet for clarity Updated formatting and content for clarity and consistency in the Globbing Cheatsheet. --- cheatsheet.md | 84 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 49 insertions(+), 35 deletions(-) diff --git a/cheatsheet.md b/cheatsheet.md index 6426e9d..9a4f3fb 100644 --- a/cheatsheet.md +++ b/cheatsheet.md @@ -1,53 +1,67 @@ -# Globbing cheatsheet +# Globbing Cheatsheet -WIP +> WIP -## Basic globbing +## Basic Globbing -| **Character** | **Description** | -| --- | --- | -| `*` | Matches any character zero or more times, except for `/` | -| `**` | Matches any character zero or more times, including `/` | -| `?` | Matches any character except for `/` one time | -| `[abc]` | Matches any characters inside the brackets. For example, `[abc]` would match the characters `a`, `b` or `c`, and nothing else. | +| **Character** | **Regex Equivalent** | **Description** | +| --- | --- | --- | +| `*` | `[^/]*` | Matches any character zero or more times, except for `/`. | +| `**` | `.*` | Matches any character zero or more times, including `/`. | +| `?` | `[^/]` | Matches any character except for `/` one time. | +| `[abc]` | `[abc]` | Matches any characters inside the brackets.[^1] | + +[^1]: For example, [abc] would match the characters `a`, `b` or `c`, and nothing else. Notes: -- `*` typically does not match dotfiles (file names starting with a `.`) unless explicitly enabled by the user [via options](#common-options) +- `*` typically does not match dotfiles (file names starting with a `.`), + unless explicitly enabled by the user [via options](#globbing-options) - `?` also typically does not match the leading dot -- More than two stars in a glob path segment are typically interpreted as _a single star_ (e.g. `/***/` is the same as `/*/`) +- More than two stars in a glob path segment are typically interpreted as _a single star_ + - e.g. `/***/` is the same as `/*/` + +## Extended Globbing -## Extended globbing +### Brace Expansion -### brace expansion +> TODO -TODO +### `extglob` -### extglob +In addition to basic globs (`*`, `*`, `?`, `[...]`), +`extglob` adds (almost) the full expressive power of standard RegEx, +allowing the use of patterns like `foo/!(a\|b)*` -| **pattern** | **regex equivalent** | **description** | -| --- | --- | --- | -| `?(pattern-list)` | `(...|...)?` | Matches zero or one occurrence of the given patterns | -| `*(pattern-list)` | `(...|...)*` | Matches zero or more occurrences of the given patterns | -| `+(pattern-list)` | `(...|...)+` | Matches one or more occurrences of the given patterns | -| `@(pattern-list)` | `(...|...)` * | Matches one of the given patterns | -| `!(pattern-list)` | N/A | Matches anything except one of the given patterns | +| **Pattern** | **Regex Equivalent** | **Description** | +| --- | --- | --- | +| `?(pattern-list)` | `(...\|...)?` | Matches zero or one occurrence of the given patterns | +| `*(pattern-list)` | `(...\|...)*` | Matches zero or more occurrences of the given patterns | +| `+(pattern-list)` | `(...\|...)+` | Matches one or more occurrences of the given patterns | +| `@(pattern-list)` | `(...\|...)` | Matches one of the given patterns | +| `!(pattern-list)` | N/A | Matches anything except one of the given patterns | -### POSIX character classes +### POSIX Character Classes -TODO +> TODO -## Globbing options +## Globbing Options Options that are commonly available on various globbing implementations. -| **Option name** | **Description** | -| --- | --- | -| `extglob` | Enable extended globs. In addition to the traditional globs (using wildcards: `*`, `*`, `?` and `[...]`), extended globs add (almost) the expressive power of regular expressions, allowing the use of patterns like `foo/!(a|b)*` | -| `dotglob` | Allows files beginning with `.` to be included in matches. This option is automatically enabled if the glob pattern begins with a dot. Aliases: `dot` (supported by: [minimatch][], [micromatch][]) | -| `failglob` | report an error when no matches are found | -| `globignore` allows you to specify patterns a glob should not match Aliases: `ignore` (supported by: [minimatch][], [micromatch][]) | -| `globstar` | recursively match directory paths (enabled by default in [minimatch][] and [micromatch][], but not in [bash][]) | -| `nocaseglob` | perform case-insensitive pathname expansion | -| `nocasematch` | perform case-insensitive matching. Aliases: `nocase` (supported by: [minimatch][], [micromatch][]) | -| `nullglob` | when enabled, the pattern itself will be returned when no matches are found. Aliases: `nonull` (supported by: [minimatch][], [micromatch][]) | +| **Option Name** | **Description** | **Alias** | **Supported By** | +| --- | --- | --- | --- | +| `extglob` | Enables [extended globbing](#extended-globbing). | | | +| `dotglob` | Allows files beginning with `.` to be included in matches. | `dot` | [minimatch], [micromatch]
(Automatically enabled if glob pattern begins with a dot) | +| `failglob` | Reports an error if no matches are found. | | | +| `globignore` | Allows you to specify patterns a glob should *not* match. | `ignore` | [minimatch], [micromatch] | +| `globstar` | Recursively matches directory paths. | | [minimatch], [micromatch]
(On by default in minimatch and micromatch, but not in [bash]) | +| `nocaseglob` | Performs case-insensitive pathname expansion. | | | +| `nocasematch` | Performs case-insensitive matching. | `nocase` | [minimatch], [micromatch] | +| `nullglob` | Returns the glob pattern itself if no matches are found. | `nonull` | [minimatch], [micromatch] | + +[minimatch]: https://github.com/isaacs/minimatch +[micromatch]: https://github.com/micromatch/micromatch +[bash]: https://www.gnu.org/software/bash/ + +