HUGO
Menu
GitHub 89737 stars Mastodon

Glob patterns

A quick reference guide to glob pattern syntax and matching rules for wildcards, character sets, and delimiters, featuring illustrative examples.

A glob pattern is a pattern used to match sets of values. It is a shorthand for specifying multiple targets at once, making it easier to work with groups of data or configurations.

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.

Match typeGlob patternTest stringMatch?
Simple wildcardimages/*.jpgimages/a.jpgtrue
Literal matchimages/a\*.jpgimages/a*.jpgtrue
Single-level wildcardimages/*/a.jpgimages/foo/a.jpgtrue
Single-level wildcardimages/*/a.jpgimages/foo/bar/a.jpgfalse
Multi-level wildcardimages/**/a.jpgimages/foo/bar/a.jpgtrue
Multi-level wildcardimages/**/a.jpgimages/a.jpgfalse
Single characterimage.???image.jpgtrue
Single characterimage.???image.aviffalse
Delimiter exclusion?atf/atfalse
Character listimages/a.[jp]pgimages/a.jpgtrue
Negated listimages/a.[!p]pgimages/a.jpgtrue
Character rangeimages/a-[a-c].jpgimages/a-b.jpgtrue
Character rangeimages/a-[a-c].jpgimages/a-z.jpgfalse
Negated rangeimages/a-[!a-c].jpgimages/a-z.jpgtrue
Pattern alternatesimages/*.{jpg,png}images/logo.pngtrue
No matchimages/*.{jpg,png}images/logo.webpfalse

The matching logic follows these rules:

  • Standard wildcard (*) matches any character except for a delimiter.
  • 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.
  • Single character (?) matches exactly one character, excluding delimiters.
  • Negation (!) matches any character except those specified in a list or range when used inside brackets.
  • Character ranges ([a-z]) match any single character within the specified range.

The delimiter is a slash (/), except when matching semantic version strings, where the delimiter is a dot (.).