Skip to content

obeattie/ohmyglob

Repository files navigation

ohmyglob

A minimal glob matching utility for Go.

ohmyglob!

GoDoc Build Status

Works internally by converting glob expressions into Regexps, which are then used to match strings.

Features

  • Customisable separators
  • * matches any number of characters, but not the separator
  • ? matches any single character, but not the separator
  • ! at the beginning of a pattern will negate the match
  • \ escapes the next character – \\ is a literal backslash
  • "Globstar" (**) matching
  • Glob sets allow matching against a set of ordered globs, with precedence to later matches

Usage

import glob "github.com/obeattie/ohmyglob"

var g glob.Glob
var err error
var doesMatch bool

// Standard, with a wildcard
g, err = glob.Compile("foo/*/baz", glob.DefaultOptions)
doesMatch = g.MatchString("foo/bar/baz") // true!
doesMatch = g.MatchString("nope") // false!

// Globstar
g, err = glob.Compile("foo/**/baz", glob.DefaultOptions)
doesMatch = g.MatchString("foo/bar/bar/baz") // true!
doesMatch = g.MatchString("foo/baz") // true!

About

A minimal glob matching utility for Go

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages