Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrBadPattern = path.ErrBadPattern
Functions ¶
func Match ¶
Match reports whether name matches the shell pattern. The pattern syntax is:
pattern: { term } term: '*' matches any sequence of non-path-separators '/**/' matches zero or more directories '?' matches any single non-path-separator character '[' [ '^' '!' ] { character-range } ']' character class (must be non-empty) starting with `^` or `!` negates the class '{' { term } [ ',' { term } ... ] '}' alternatives c matches character c (c != '*', '?', '\\', '[') '\\' c matches character c character-range: c matches character c (c != '\\', '-', ']') '\\' c matches character c lo '-' hi matches character c for lo <= c <= hi
Match returns true if `name` matches the file name `pattern`. `name` and `pattern` are split on forward slash (`/`) characters and may be relative or absolute.
Match requires pattern to match all of name, not just a substring. The only possible returned error is ErrBadPattern, when pattern is malformed.
A doublestar (`**`) should appear surrounded by path separators such as `/**/`. A mid-pattern doublestar (`**`) behaves like bash's globstar option: a pattern such as `path/to/**.txt` would return the same results as `path/to/*.txt`. The pattern you're looking for is `path/to/**/*.txt`.
Note: this is meant as a drop-in replacement for path.Match() which always uses '/' as the path separator. If you want to support systems which use a different path separator (such as Windows), what you want is PathMatch(). Alternatively, you can run filepath.ToSlash() on both pattern and name and then use this function.
Note: users should _not_ count on the returned error, doublestar.ErrBadPattern, being equal to path.ErrBadPattern.
func ValidatePattern ¶
Validate a pattern. Patterns are validated while they run in Match(), PathMatch(), and Glob(), so, you normally wouldn't need to call this. However, there are cases where this might be useful: for example, if your program allows a user to enter a pattern that you'll run at a later time, you might want to validate it.
ValidatePattern assumes your pattern uses '/' as the path separator.
Types ¶
This section is empty.