java nio 否定 glob 模式

java nio negate a glob pattern

fileSystem.getPathMatcher("glob:${pattern}").matches(path.getFileName())}

我想匹配所有不匹配 "ts.*" 的东西。 java 中的 glob 的语法是什么? (在有人建议我改用正则表达式之前,我需要使用 glob)

如果我们查看 official documentation,我们会发现否定某物的唯一方法是使用括号表达式。

If the character after the [ is a ! then it is used for negation so [!a-c] matches any character except "a", "b", or "c".

因此在您的情况下,模式可能类似于 {[!t]*,t[!s]*,ts[!.]*}

[!t][!s][!.]* 这样的模式是行不通的,因为它也不会匹配以 as..

开头的文件