我正在尝试编写一个 Search 类,该类搜索包含具有 id 属性的 dataItems 的列表,以查找针对此类 id 列表的命中。
但我无法让正则表达式正常工作。我尝试打印包含我的正则表达式的字符串变量,然后匹配它而不是变量,这使得它出于某种奇怪的原因工作。
我用这种方法做到这一点:
private <D extends dataItem> boolean subSearch(D d){
boolean b = false;
for(String sf: d.getSearchField(searchF)){
System.out.println(sf); //String of id I match against
System.out.println(searchQ); //Prints "(A0A5E1)|(A4QPC6)|(A6NC42)|(A6NMB1)|(A6NI73)"
System.out.println(sf.matches("(A0A5E1)|(A4QPC6)|(A6NC42)|(A6NMB1)|(A6NI73)"));//Prints true
b = b || sf.matches(searchQ);
if(sf.matches(searchQ)){ //Does not match when sf.matches("(A0A5E1)|(A4QPC6)|(A6NC42)|(A6NMB1)|(A6NI73)") matches
System.out.println(searchQ);
System.out.println(sf);
}
}
return b;
}
关于 sf.matches(searchQ) 出了什么问题的任何想法?