使用正则表达式判断几个给定的单词是否在一个单词序列中存在,条件是预先不知道单词出现的次数和顺序
如,String words="this is a perfect paper for the data management!"
String isExist_words="paper management";
判断words中是否出现paper management这两个单词,谢谢
如,String words="this is a perfect paper for the data management!"
String isExist_words="paper management";
判断words中是否出现paper management这两个单词,谢谢
private static boolean isExist(){
boolean rtn=true;
String isExist_words="paper manage ";
String words = "this is a perfect paper paper for the data management!";
String regex="\\b\\w+\\b";
List<String> list1=new ArrayList<String>();
List<String> list2=new ArrayList<String>();
Matcher m1=Pattern.compile(regex).matcher(isExist_words);
while(m1.find()){
list1.add(m1.group());
}
Matcher m2=Pattern.compile(regex).matcher(words);
while(m2.find()){
list2.add(m2.group());
}
if(list1.size()<=0||list2.size()<=0)
rtn=false;
for(String i:list1){
if(!list2.contains(i))
rtn=false;
}
return rtn;
}