Java正则表达式匹配不起作用

Java正则表达式匹配不起作用,java,regex,match,Java,Regex,Match,我正在尝试编写一个搜索类来搜索包含具有id属性的数据项的列表,以查找针对此类id列表的点击 但是我不能让正则表达式正常工作。我试着打印包含正则表达式的字符串变量,然后与之匹配,而不是因为某种奇怪的原因使其工作的变量 我是这样做的: private <D extends dataItem> boolean subSearch(D d){ boolean b = false; for(String sf: d.getSearchField(searchF)){

我正在尝试编写一个搜索类来搜索包含具有id属性的数据项的列表,以查找针对此类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;
}
私有布尔子搜索(D){
布尔b=假;
对于(字符串sf:d.getSearchField(searchF)){
System.out.println(sf);//匹配的id字符串
System.out.println(searchQ);//打印“(A0A5E1)|(A4QPC6)|(A6NC42)|(A6NMB1)|(A6NI73)”
System.out.println(sf.matches(((A0A5E1)|(A4QPC6)|(A6NC42)|(A6NMB1)|(A6NI73)”);//打印为真
b=b | | sf.匹配(searchQ);
如果(sf.matches(searchQ)){//在sf.matches(((A0A5E1)|(A4QPC6)|(A6NC42)|(A6NMB1)|(A6NI73)”匹配时不匹配
System.out.println(searchQ);
系统输出打印项次(sf);
}
}
返回b;
}

你知道sf.matches(searchQ)有什么问题吗?

我看不出有什么问题。我甚至在本地执行了这个命令(只有for循环中的主体),并且
if(sf.matches(searchQ))
为我返回true


我相信
searchQ
没有正确的正则表达式

sf的值是多少?如果
sf.matches(((A0A5E1)|(A4QPC6)|(A6NC42)|(A6NMB1)|(A6NI73)”)
为true,searchQ为
(A0A5E1)|(A4QPC6)|(A6NMB1)|(A6NI73)”
sf.matches(searchQ)
也必须为true。id字符串。像“A0A5E1”、“A4QPC6”或其他一些不在我的搜索列表中的id。我已经检查过了,它确实打印了这些ID。您希望匹配的整个字符串的示例是什么?并且
d.getSearchField
返回一个
字符串[]
?您是对的。“searchQ”包含“\r”字符,在打印字符串时未显示该字符。