{"id":13395196,"url":"https://github.com/begin/globbing","last_synced_at":"2025-03-13T20:31:57.798Z","repository":{"id":152157580,"uuid":"70743841","full_name":"begin/globbing","owner":"begin","description":"Introduction to \"globbing\" or glob matching, a programming concept that allows \"filepath expansion\" and matching using wildcards. ","archived":false,"fork":false,"pushed_at":"2019-05-23T09:39:26.000Z","size":23,"stargazers_count":148,"open_issues_count":0,"forks_count":19,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-07-31T17:23:42.087Z","etag":null,"topics":["bash","brace-expansion","cheatsheet","extended-globs","extglob","filename-expansion","glob","glob-matching","glob-pattern","globbing","guide","pattern","regex","regular-expression","wildcard"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/begin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-10-12T21:37:59.000Z","updated_at":"2024-07-10T09:01:07.000Z","dependencies_parsed_at":"2024-01-13T17:11:44.118Z","dependency_job_id":"80cddfba-1af5-455c-a2dc-cd29c91391e1","html_url":"https://github.com/begin/globbing","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/begin%2Fglobbing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/begin%2Fglobbing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/begin%2Fglobbing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/begin%2Fglobbing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/begin","download_url":"https://codeload.github.com/begin/globbing/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243478335,"owners_count":20297237,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","brace-expansion","cheatsheet","extended-globs","extglob","filename-expansion","glob","glob-matching","glob-pattern","globbing","guide","pattern","regex","regular-expression","wildcard"],"created_at":"2024-07-30T17:01:45.857Z","updated_at":"2025-03-13T20:31:57.291Z","avatar_url":"https://github.com/begin.png","language":null,"readme":"# globbing\n\n\u003e Cheatsheet and introduction to \"globbing\", a programming concept that involves the use of wildcards and special characters for matching and filtering.\n\n## Table of contents\n\n- [Contributing](#contributing)\n- [What is \"globbing\"?](#what-is-globbing)\n- [Wildcards](#wildcards)\n- [Extended globbing](#extended-globbing)\n  * [brace expansion](#brace-expansion)\n- [extglobs](#extglobs)\n  * [POSIX character classes](#posix-character-classes)\n  * [Regular expressions](#regular-expressions)\n    + [regex character classes](#regex-character-classes)\n    + [regex groups](#regex-groups)\n- [Common options](#common-options)\n- [Caveats](#caveats)\n- [Resources](#resources)\n  * [Guides and documentation](#guides-and-documentation)\n  * [Tools and software](#tools-and-software)\n  * [Related concepts](#related-concepts)\n- [TODO](#todo)\n\n_(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_\n\n## Contributing\n\nWe love contributors!\n\n[Pull requests](../../issues/) to add documentation, links to tools, corrections or anything else are warmly accepted and gratefully appreciated!\n\nToo busy to contribute directly, but still want to show your support? Please consider starring this project or tweeting about it!\n\n## What is \"globbing\"?\n\nThe term \"globbing\", also referred to as \"glob matching\" or \"filepath expansion\", is a programming concept that describes the process of using wildcards, referred to as \"glob patterns\" or \"globs\", for matching file paths or other similar sets of strings.\n\nSimilar to [regular expressions](http://www.regular-expressions.info/), but much simpler and limited in scope, glob patterns are defined using a combination of special characters, or wildcards, alongside literal (non-matching) characters. For example, the glob pattern `*.txt` would match all files in a directory with a `.txt` file extension.\n\n**Globbing syntax**\n\nTODO: describe wildcards vs. extended globbing, and segue to following sections\n\n* wildcards\n* extended globbing\n\n## Wildcards\n\nThe commonly supported characters supported across globbing implementations for basic wildcard matching are `*`, `?` and a simplified version of regex brackets for matching any of a given set of characters.\n\nAlthough many different globbing implementations exist across a number of different languages and environments, the following table summarizes the most commonly supported basic globbing features.\n\n| **Character** | **Description** | \n| --- | --- |\n| `*` | Matches any character zero or more times, except for `/`. |\n| `**` | Matches any character zero or more times, including `/`. |\n| `?` | Matches any character one time |\n| `[abc]` | Matches any of the specified characters (in this case, `a`, `b` or `c`) |\n\nSpecial exceptions:\n\n* `*` typically does not match dotfiles (file names starting with a `.`) unless explicitly enabled by the user [via options](#common-options)\n* `?` also typically does not match the leading dot\n* More than two stars in a glob path segment are typically interpreted as _a single star_ (e.g. `/***/` is the same as `/*/`)\n\n**Implementations**\n\nGlobbing is typically enabled using third-party libraries. A notable exception, [bash](https://github.com/felixge/node-bash), provides built-in support for basic globbing.\n\nTODO: add list of implementations\n\n**Additional reading**\n\n* [Wildcards - GNU/Linux Command-Line Tools Summary](http://tldp.org/LDP/GNU-Linux-Tools-Summary/html/x11655.htm#WILDCARDS)\n\n## Extended globbing\n\nIn addition to [wildcard matching](#wildcards), extended globbing describes the addition of more advanced matching features, such as:\n\n* brace expansion\n* extglobs\n* POSIX character classes\n* regular expressions\n\nTBC...\n\n### brace expansion\n\nIn simple cases, brace expansion appears to work the same way as the logical `OR` operator. For example, `(a|b)` will achieve the same result as `{a,b}`.\n\nHere are some powerful features unique to brace expansion (versus character classes):\n\n* range expansion: `a{1..3}b/*.js` expands to: `['a1b/*.js', 'a2b/*.js', 'a3b/*.js']`\n* nesting: `a{c,{d,e}}b/*.js` expands to: `['acb/*.js', 'adb/*.js', 'aeb/*.js']`\n\nTBC...\n\nVisit the [braces](https://github.com/micromatch/braces) library for more examples and information about brace expansion.\n\n## extglobs\n\nTBC...\n\nAs described by the bash man page:\n\n| **pattern** | **regex equivalent** | **matches** | \n| --- | --- | --- |\n| `?(foo)` | `(foo)?` | zero or one occurrence of the given patterns |\n| `*(foo)` | `(foo)*` | zero or more occurrences of the given patterns |\n| `+(foo)` | `(foo)+` | one or more occurrences of the given patterns |\n| `@(foo)` | `(foo)` \u003csup\u003e*\u003c/sup\u003e | one of the given patterns |\n| `!(foo)` | `^(?:(?!(foo)$).*?)$` | anything except one of the given patterns |\n\n\u003csup\u003e\u003cstrong\u003e*\u003c/strong\u003e\u003c/sup\u003e Note that `@` isn't a RegEx character.\n\n**Example implementations**\n\n* [extglob](https://github.com/micromatch/extglob) - extended glob parser and matcher for node.js\n\n### POSIX character classes\n\nPOSIX character classes, or \"bracket expressions\", provide a way of defining regular expressions using something closer to plain english.\n\nFor example, the pattern `[[:alpha:][:digit:]]` would match `a1`, but not `aa`.\n\nTBC...\n\n**Example implementations**\n\n* [expand-brackets](https://github.com/jonschlinkert/expand-brackets), node.js API for parsing and matching POSIX bracket expressions\n\n### Regular expressions\n\nThis section describes matching using [regular expressions](http://www.regular-expressions.info/) _as it relates to globbing_.\n\n#### regex character classes\n\nWhen regex character classes are used in glob patterns, with the exception of brace expansion (`{a,b}`, `{1..5}`, etc), most of the special characters convert directly to regex, so you can expect them to follow the same rules and produce the same results as regex.\n\nFor example, given the list: `['a.js', 'b.js', 'c.js', 'd.js', 'E.js']`:\n\n* `[ac].js`: matches both `a` and `c`, returning `['a.js', 'c.js']`\n* `[b-d].js`: matches from `b` to `d`, returning `['b.js', 'c.js', 'd.js']`\n* `[b-d].js`: matches from `b` to `d`, returning `['b.js', 'c.js', 'd.js']`\n* `a/[A-Z].js`: matches and uppercase letter, returning `['a/E.js']`\n\nHowever, there is\n\nLearn about [regex character classes][character-classes].\n\n#### regex groups\n\nGiven `['a.js', 'b.js', 'c.js', 'd.js', 'E.js']`:\n\n* `(a|c).js`: would match either `a` or `c`, returning `['a.js', 'c.js']`\n* `(b|d).js`: would match either `b` or `d`, returning `['b.js', 'd.js']`\n* `(b|[A-Z]).js`: would match either `b` or an uppercase letter, returning `['b.js', 'E.js']`\n\nAs with regex, parentheses can be nested, so patterns like `((a|b)|c)/b` will work. But it might be easier to achieve your goal using brace expansion.\n\n## Common options\n\nThe following options are commonly available on various globbing implementations.\n\n| **Option name** | **Description** | \n| --- | --- |\n| `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)*` |\n| `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](https://github.com/isaacs/minimatch), [micromatch](https://github.com/micromatch/micromatch)) |\n| `failglob` | report an error when no matches are found |\n| `globignore` | allows you to specify patterns a glob should not match  Aliases: `ignore` (supported by: [minimatch](https://github.com/isaacs/minimatch), [micromatch](https://github.com/micromatch/micromatch)) |\n| `globstar` | recursively match directory paths (enabled by default in [minimatch](https://github.com/isaacs/minimatch) and [micromatch](https://github.com/micromatch/micromatch), but not in [bash](https://github.com/felixge/node-bash)) |\n| `nocaseglob` | perform case-insensitive pathname expansion |\n| `nocasematch` | perform case-insensitive matching. Aliases: `nocase` (supported by: [minimatch](https://github.com/isaacs/minimatch), [micromatch](https://github.com/micromatch/micromatch)) |\n| `nullglob` | when enabled, the pattern itself will be returned when no matches are found. Aliases: `nonull` (supported by: [minimatch](https://github.com/isaacs/minimatch), [micromatch](https://github.com/micromatch/micromatch)) |\n\n## Caveats\n\n_WIP_\n\nLike [regular expressions](http://www.regular-expressions.info/), glob patterns are a type of [regular language](https://en.wikipedia.org/wiki/Regular_language) that must first be interpreted by a computer program before any actual matching takes place. This introduces two areas of risk:\n\n* interpreting patterns:\n* performing matches:\n\n**Interpreting patterns**\n\nTODO (The process of parsing and compiling a glob pattern into a regular expression...)\n\n**Performing matches**\n\nTODO (The process of matching the compiled regular expression against a set of strings)\n\n**Risks**\n\n* Intentional denial-of-service (DoS) attacks from hackers\n* Unintentional denial-of-service (DoS) attacks from agressively greedy wildcard patterns\n\n## Resources\n\nLearn more about globbing.\n\n### Guides and documentation\n\n* [GNU/Linux Command-Line Tools Summary: Wildcards](http://tldp.org/LDP/GNU-Linux-Tools-Summary/html/x11655.htm)\n* [Bash: globbing](http://tldp.org/LDP/abs/html/globbingref.html)\n* [Wikipedia: glob (programming)](https://en.wikipedia.org/wiki/Glob_(programming))\n* [Linux Programmer's Manual: GLOB(7)](http://man7.org/linux/man-pages/man7/glob.7.html)\n\n### Tools and software\n\n| **Name** | **Programming language** | \n| --- | --- |\n| [bash-glob](https://github.com/micromatch/bash-glob) | JavaScript/node.js |\n| [brace-expansion](https://github.com/juliangruber/brace-expansion) | JavaScript/node.js |\n| [braces](https://github.com/micromatch/braces) | JavaScript/node.js |\n| [expand-brackets](https://github.com/micromatch/expand-brackets) | JavaScript/node.js |\n| [glob](https://github.com/isaacs/node-glob) | JavaScript/node.js |\n| [micromatch](https://github.com/micromatch/micromatch) | JavaScript/node.js |\n| [minimatch](https://github.com/isaacs/minimatch) | JavaScript/node.js |\n| [nanomatch](https://github.com/micromatch/nanomatch) | JavaScript/node.js |\n\n### Related concepts\n\nThe following concepts are similar to or include the concept of globbing:\n\n* [regular expressions](http://www.regular-expressions.info/)\n* [tilde expansion](https://www.gnu.org/software/bash/manual/html_node/Tilde-Expansion.html)\n* [Wikipedia: kleene star](https://en.wikipedia.org/wiki/Kleene_star)\n* [Wikipedia: KornShell (ksg)](https://en.wikipedia.org/wiki/KornShell)\n\n## TODO\n\n* [ ] cheatsheet\n* [ ] what is globbing\n* [ ] wildcards\n* [ ] extglobs\n* [ ] posix brackets\n* [ ] braces\n* [ ] options\n","funding_links":[],"categories":["Others"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbegin%2Fglobbing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbegin%2Fglobbing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbegin%2Fglobbing/lists"}