Closed vatine closed 3 years ago
I believe the negation is documented as ^
: https://play.golang.org/p/9zwuCeWNtXS
filepath.Glob does call Match: https://github.com/golang/go/blob/go1.15.2/src/path/filepath/match.go#L328
I'm not sure if these patterns are changeable without breaking any existing Go programs. See also the long discussion at #11862.
/cc @robpike @rsc
filepath.Match
documents the exact syntax that it supports: https://golang.org/pkg/path/filepath/#Match .
I agree that in the POSIX shell definition, !
negates a character class and ^
does not. I guess we got that wrong. (In the bash shell, both !
and ^
negate a character class).
Unfortunately, we can't change it now. Sorry.
Would it be worth keeping "allow both !
and ^
for character class negation" in mind for Go2?
Well, path/filepath/v2, but, sure.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Based on docuemntation and the Go playground, yes. https://play.golang.org/p/WHq5MYYn_yf
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I passed the pattern
"ga*[!k]"
tofilepath.Match
expecting it to not match the string"gazonk"
(as it clearly states it must match the entire pattern, and the glob-like syntax for a negated character class is[!...]
). It turns out that filepath.Match actually uses regexp-like syntx for character classes.https://play.golang.org/p/WHq5MYYn_yf
What did you expect to see?
I expected a function that says "shell file name pattern" to understand glob patterns. Especially since filepath.Glob says "uses the same pattern as Match".
What did you see instead?
I saw a function that partially uses glob patterns and partially (well, specifically for character classes) uses regexp patterns.