glob icon indicating copy to clipboard operation
glob copied to clipboard

Unexpected result matching windows paths

Open nirekin opened this issue 6 years ago • 2 comments

I am trying to match a windows path but the given result is not the expected one:

g := glob.MustCompile("C:\\p1\\p2\\templateTarget[12].yaml")
g.Match("C:\\p1\\p2\\templateTarget1.yaml") // false

I find a workaround replacing all the \\ by / but it's kind of annoying...

g := glob.MustCompile("C:/p1/p2/templateTarget[12].yaml")
g.Match("C:/p1/p2/templateTarget1.yaml") // true

nirekin avatar Jun 07 '19 06:06 nirekin

Hi @nirekin, there is a QuoteMeta() call for such cases. Ping me if it does not help :)

gobwas avatar Jun 07 '19 07:06 gobwas

Hi @gobwas,

I have tried to use it but I cant figure how it could be helpful in that case. Quoting the glob pattern meta characters has no effects, not good nor bad...

g := glob.MustCompile(glob.QuoteMeta("C:\\p1\\p2\\templateTarget[12].yaml"))
g.Match("C:\\p1\\p2\\templateTarget1.yaml") // false

Do you have any additional hint or example?

nirekin avatar Jun 07 '19 07:06 nirekin