A lightweight glob wildcard pattern matching utility for Go, when regex is an overkill
go get github.com/co89757/glob4go
The glob syntax is largely similar to UNIX globbing execept for a few unsupported syntax
*
:matches any number of characters?
:matches a single character[...]
:matches a range/group of characters. For example,[0-9]
matches any single-digit number,[axz]
matches any character in 'a','x','z'[^...]
:inverse range/group match. The inverse of the above range match case. It matches any character not in the range- all keywords above can be escaped by
\
, i.e.\?
matches a literal?
Currently, the API of the pacakge is really simple:
glob4go.Glob(pattern, str []byte, ignoreCase bool)
Here is an example usage
import (
"github.com/co89757/glob4go"
)
func globExample(){
var match bool
pattern := []byte("abcd[0-9]?")
s1 := []byte("abcd8e")
//case sensitive match
match = glob4go.Glob(pattern,s1,false) // true, it is a match
s2 := []byte("AbCd8e")
match = glob4go.Glob(pattern, s2, true) // true, it is a match when ignore case
}
- Performance and benchmarking
- Add unicode support