Package wildmatch solves inclusion problem for the wildcard path patterns.
Supported patterns:
*
- any characters. zero or more.
?
- any character. exactly one.
/
- folder separator.
/**/
- any number of nested folders
For example a/b/*
is a subset of a/?/*
but not a subset of a/*
.
This is because *
includes any character withing folder/file name.
For multiple folders matching use /**/
pattern which means any number of nested folders.
import (
"fmt"
"github.com/stretchr/testify/assert"
)
// Examples
func ExampleIsSubset_positive() {
fmt.Println(Wildcard("a/x?/cd").IsSubsetOf("a/*/c?"))
// Output: true
}
func ExampleIsSubset_negative() {
fmt.Println(Wildcard("a/*/c").IsSubsetOf("a/?/c"))
// Output: false
}
func ExampleIsSubsetOfAny() {
ans, _ := Wildcard("a*.txt").IsSubsetOfAny(Wildcard("*"), Wildcard("*.txt"),
Wildcard("*.t?t"), Wildcard("*.?x?"))
fmt.Println(ans)
// Output: *.txt
}