java nio negate a glob pattern

筅森魡賤 提交于 2019-12-11 09:42:40

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!