1
讓我們:爲什麼glob:*匹配PathMatcher中的任何路徑?
Path path = Paths.get("C:\\1.txt");
下面的代碼打印 「真」:
PathMatcher matcher = FileSystems.getDefault().getPathMatcher("regex:.*");
System.out.println(matcher.matches(path));
,但下面的代碼打印出 「假」:
PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:*");
System.out.println(matcher.matches(path));
爲什麼?
我期待在兩種方法中都有true
。
據Glob page from Wikipedia,通配符*
表示:
任意數目的字符,包括無
詳細匹配:
- 的Java 8
- 的Windows 7
與其查閱維基百科關於glob的含義,我強烈建議[查看'getPathMatcher']的文檔(https://docs.oracle.com/javase/7/docs/api/爪哇/ NIO /文件/ FileSystem.html#getPathMatcher(java.lang.String中))。但是它也有類似的說法:*「\ *字符與名稱組件的零個或多個字符匹配,不會跨越目錄邊界。」*另請注意:*「\ * \ *字符匹配零個或多個跨越目錄邊界的字符。」*也許你想'**'(不知道,從來沒有使用'PathMatcher')。 –
此外,您從Wikipage鏈接:COMMAND.COM和cmd.exe具有大多數常見語法有一些限制:沒有[...]和*可能只出現在模式的結尾,而不是# –
@JorgeCampos:我的Windows 8系統上的'cmd.exe'在模式開始處用'*'表示很好。 –