minimatch-cheat-sheet

July 15, 2014 ยท View on GitHub

A cheat sheet for minimatch.

Basic

  • * matches any string, not including than path separator
  • ** matches any string, including path separators
  • ? matches single character other than path separator
PatternMatchesDoes not match
xxx.*xxx.yyy, xxx.y.zabcxxx.yyy, xxx.y/z
xxx/*/yyyxxx/abc/yyyxxx/yyy, xxx/abc/def/yyy, xxx/.abc/yyy
xxx/**/yyyxxx/abc/yyy, xxx/yyy, xxx/abc/def/yyyxxx/.abc/yyy
xxx/**yyyxxx/yyyxxx/abc/yyy, xxx/abc/def/yyy, xxx/.abc/yyy
x?yxAyxy, xABy, x/y

Braces

  • {foo,bar} matches "foo" and "bar"
  • {1..3} matches "1", "2" and "3"
PatternMatchesDoes not match
{foo,bar}foo, barbaz
{x,y/*}/zx/z, y/a/zy/z
foo{1..3}foo1, foo2, foo3foo, foo0

Negation

  • !-prefixed patterns invert match
PatternMatchesDoes not match
!abca, xyzabc

Comments

  • #-prefixed patterns are treated as comments and match nothing
  • \# to escape
PatternMatchesDoes not match
#abcabc, #abc
\#abc#abcabc

Extglob

  • +(pattern) matches one or more repetition of pattern (like /(pattern)+/)
  • *(pattern) matches zero or more repetition of pattern (like /(pattern)*/)
  • ?(pattern) matches zero or one repetition of pattern (like /(pattern)?/)
  • @(pattern) matches pattern (like /(pattern)/)
  • !(pattern) matches anything except the pattern (like /(?!pattern)/)
  • pattern can be joined by | (like /(foo|bar)/)
PatternMatchesDoes not match
a+(xy)axy, axyxya
a*(xy)a, axy, axyxy
a@(xy)axya, axyxy
a!(xy)axaxy, axyz
a+(x|y*z)axx, ayzxyzxx, axyAAAzaxy, a