Skip to content

Instantly share code, notes, and snippets.

@mrpharderwijk
Last active April 16, 2019 09:30
Show Gist options
  • Save mrpharderwijk/0b67296af5c43ccb26c71fb7d4008454 to your computer and use it in GitHub Desktop.
Save mrpharderwijk/0b67296af5c43ccb26c71fb7d4008454 to your computer and use it in GitHub Desktop.
Glob patterns

Glob Primer

"Globs" are the patterns you type when you do stuff like ls *.js on the command line, or put build/* in a .gitignore file.

Before parsing the path part patterns, braced sections are expanded into a set. Braced sections start with { and end with }, with any number of comma-delimited sections within. Braced sections may contain slash characters, so a{/b/c,bcd} would expand into a/b/c and abcd.

The following characters have special magic meaning when used in a path portion:

  • * Matches 0 or more characters in a single path portion
  • ? Matches 1 character
  • [...] Matches a range of characters, similar to a RegExp range. If the first character of the range is ! or ^ then it matches any character not in the range.
  • !(pattern|pattern|pattern) Matches anything that does not match any of the patterns provided.
  • ?(pattern|pattern|pattern) Matches zero or one occurrence of the patterns provided.
  • +(pattern|pattern|pattern) Matches one or more occurrences of the patterns provided.
  • *(a|b|c) Matches zero or more occurrences of the patterns provided
  • @(pattern|pat*|pat?erN) Matches exactly one of the patterns provided
  • ** If a "globstar" is alone in a path portion, then it matches zero or more directories and subdirectories searching for matches. It does not crawl symlinked directories.

source

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment