问题
fileSystem.getPathMatcher("glob:${pattern}").matches(path.getFileName())}
I want to match everything that DOES NOT match "ts.*". What's the syntax for that for a glob in java? (Before anyone suggests I use regex instead, I am required to use a glob)
回答1:
If we look at the official documentation we find that the only way how to negate something is by using bracket expressions.
If the character after the [ is a ! then it is used for negation so [!a-c] matches any character except "a", "b", or "c".
So in your case the pattern could be something like {[!t]*,t[!s]*,ts[!.]*}
.
A pattern like [!t][!s][!.]*
would not work, because it would also not match files beginning with, e.g., as.
.
来源:https://stackoverflow.com/questions/48916176/java-nio-negate-a-glob-pattern