错误与连接字符串匹配

时间:2015-04-26 16:33:20

标签: java

假设你有一个字符串

StringA = "a,b,c,d,e"

并且想要查找StringA是否在此特定顺序中包含“a”和“c”,首先是“a”和第二个(某处......)“c”。为此,我使用

StringA.matches(".*" + "a" + ".*" + "c" +".*") 

但没有结果。是否存在语法错误;

更新:我提供了我使用的代码

for (i = 0; i < b; i++) {
    if (itinList.get(i).get(0).equals(username)) {

        itinList5.add(itinList.get(i));

        for (j =0; j < b; j++) {

        if(!itinList.get(j).get(0).equals(username) && itinList.get(j).get(18)
                .matches(".*?itinList.get(j).get(1).*?itinList.get(j).get(5).*")){
            itinList5.add(itinList.get(j));

        }
        }

    }
}

2 个答案:

答案 0 :(得分:0)

尝试类似:

if (stringA.matches(".*?a.*?c.*")) {
     //...
}

答案 1 :(得分:0)

Pattern p=Pattern.compile(".*?a,.*c.*?");
Matcher m=p.matcher(inp);
System.out.println(m.matches());
>> Above sysop will display true or false
相关问题