java nio否定glob模式 [英] java nio negate a glob pattern

查看:82
本文介绍了java nio否定glob模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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)

推荐答案

如果我们查看

If we look at the official documentation we find that the only way how to negate something is by using bracket expressions.

如果[后面的字符是!!然后它用于求反,因此[!a-c]匹配除"a","b"或"c"之外的任何字符.

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[!.]*}.

So in your case the pattern could be something like {[!t]*,t[!s]*,ts[!.]*}.

[!t][!s][!.]*这样的模式将不起作用,因为它也不会匹配以as.开头的文件.

A pattern like [!t][!s][!.]* would not work, because it would also not match files beginning with, e.g., as..

这篇关于java nio否定glob模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆