tree: 12b48b947d7cdfd08068b5ee896b39dec3faac0b [path history] [tgz]
  1. test/
  2. .gitignore
  3. .travis.yml
  4. doublestar.go
  5. doublestar_test.go
  6. LICENSE
  7. README.google
  8. README.md
go/src/github.com/bmatcuk/doublestar/README.md

Release Build Status codecov.io

doublestar

doublestar is a golang implementation of path pattern matching and globbing with support for “doublestar” (aka globstar: **) patterns.

doublestar patterns match files and directories recursively. For example, if you had the following directory structure:

grandparent
`-- parent
    |-- child1
    `-- child2

You could find the children with patterns such as: **/child*, grandparent/**/child?, **/parent/*, or even just ** by itself (which will return all files and directories recursively).

Installation

doublestar can be installed via go get:

go get github.com/bmatcuk/doublestar

To use it in your code, you must import it:

import "github.com/bmatcuk/doublestar"

Functions

Match

func Match(pattern, name string) (bool, error)

Match returns true if name matches the file name pattern (see below). name and pattern are split on forward slash (/) characters.

PathMatch

func PathMatch(pattern, name string) (bool, error)

PathMatch returns true if name matches the file name pattern (see below). The difference between Match and PathMatch is that PathMatch will automatically use your system's path separator to split name and pattern.

Glob

func Glob(pattern string) ([]string, error)

Glob finds all files and directories in the filesystem that match pattern (see below).

Patterns

doublestar supports the following special terms in the patterns:

Special TermsMeaning
*matches any sequence of non-path-separators
**matches any sequence of characters, including path separators
?matches any single non-path-separator character
[class]matches any single non-path-separator character against a class of characters (see below)
{alt1,...}matches a sequence of characters if one of the comma-separated alternatives matches

Any character with a special meaning can be escaped with a backslash (\).

Character Classes

Character classes support the following:

ClassMeaning
[abc]matches any single character within the set
[a-z]matches any single character in the range
[^class]matches any single character which does not match the class