每次我尝试运行此代码在文本文件中查找模式时,都会不断得到“找不到这样的元素”的结果。我想可能是模式不正确,最初使用的是p1和p2,但尝试了p3和p4,没有改变任何东西。
try {
Scanner scnr = new Scanner(new File(FILENAME));
//("^(\\d{1}[- .]?){3}$")
Pattern p1 = Pattern.compile("[0-9]+\\s[0-9]+\\s[0-9]+$");
Pattern p2 = Pattern.compile("[0-9]+\\s[0-9]+\\s[0-9]+\\s[0-9]+$");
Pattern p3 = Pattern.compile("^(\\d{1}[ ]?){3}$");
Pattern p4 = Pattern.compile("^(\\d{1}[ ]?){4}$");
clear();
while (scnr.hasNextInt()) {
if(p3.matcher(scnr.nextLine()).find()){
Assign a = new Assign(scnr);
puzzle.assign(a);
stackUE.push(a);
} else if(p4.matcher(scnr.nextLine()).find())
{
RelEntry re = new RelEntry(scnr);
puzzle.addRelation(re);
stackUE.push(re);
}
} scnr.close();
System.out.println("game loaded from file");
} catch (IOException e) {
System.out.println("an input output error occurred");
}
}
暂无答案!
目前还没有任何答案,快来回答吧!