java - 为什么没有 glob :* match any path in PathMatcher?

标签 java regex glob

让我们:

Path path = Paths.get("C:\\1.txt");

以下代码打印“true”:

PathMatcher matcher = FileSystems.getDefault().getPathMatcher("regex:.*");
System.out.println(matcher.matches(path));

但以下代码打印“false”:

PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:*");
System.out.println(matcher.matches(path));
为什么?

我期望这两种方法都具有true

根据Glob page from Wikipedia ,通配符*的意思是:

matches any number of any characters including none

详细信息:

  • Java 8
  • Windows 7

最佳答案

正如 @T.J Crowder 所说,你应该很好地接受这个:

PathMatcher matcher2 = FileSystems.getDefault().getPathMatcher("glob:**");
System.out.println(matcher2.matches(path));

有关更多信息,请参阅 this其中说:

The ** characters matches zero or more characters crossing directory boundaries.

关于java - 为什么没有 glob :* match any path in PathMatcher?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37724969/

相关文章:

java - Java Regex 中的声明差异?

java - JFreeChart 相对缩放

javascript - 分解 JavaScript 中的数学表达式

regex - grep 出现 n 次给定字符的行

Python Glob.glob : a wildcard for the number of directories between the root and the destination

java - 可以在 Eclipse 命令行应用程序中隐藏 JVM 终止向导

java - 比较两个具有 Double.positive_infinity 值的变量是否合法?

ruby - 如何匹配 URL 但从匹配中排除终止符?

PHP array_walk什么都不做?

java - Java 路径中的星号