【正则表达】同时包含2个甚至多个关键字 content.contains(keyword1)&&content.contains(keyword2)

有三个字符串如何匹配同时包含两个关键字的字符串

str1 = "this is the first check run" str2 = "the first run" str3 = "the first time runing" 有两个关键字(“first ”、”check “) 正则表达式怎么写 然后匹配到str1
// regExp (?=.*我是谁)(?=.*C)^.*$
// java code
List<String> list = Arrays.asList(new String[]{
     
    "this is the first check run",
    "the first run",
    "the first time runing"
});
 
List<String> matches = new ArrayList<String>();
 
for(String word : list){
     
    //包含check且包含first
    if(word.matches("(?=.*check)(?=.*first)^.*$"))
        matches.add(word);
}
 
System.out.println(Arrays.toString(matches.toArray()));

猜你喜欢

转载自blog.csdn.net/u013346007/article/details/80855070