0
我想匹配結束的.xsd但不是在form.xsd我用下面的正則表達式的字符串列表正則表達式負回顧後:在Java中
ArrayList<String> files = new ArrayList<String>();
files.add("/abadc/asdd/wieur/file1.form.xsd");
files.add("/abadc/asdd/wieur/file2.xsd");
Pattern pattern = Pattern.compile("(?<!form{0,6})\\.xsd$");
for (String file : files) {
Matcher matcher = pattern.matcher(file);
if(matcher.find())
{
System.out.println("Found >>>> "+file);
}
}
我希望文件2被打印出來,但我做的沒有得到任何結果。我在這裏做錯了什麼?我在一個在線的java regEx Tester中嘗試了相同的表達式,我得到了預期的結果,但是我沒有在我的程序中得到結果。
可以請你解釋我爲什麼需要+。而做一個消極的後臺。我的意思是我只想找到其中有form.xsd的模式吧? 。+現在說那個somethingform.xsd不是我想要的。從那以後,它也會找到abcdform.xsd,但我只想找到abcd.form.xsd。有沒有我的正則表達式會失敗的情況。謝謝回覆。 – Rush