以下の方法は仕事をしますが、あまり効率的ではありません。
これを行うためのよりエレガントなソリューションを知っている人はいますか?
私はこのようなことをいじりましたが、今のところ運がありません: /^(foo|bar|[[:space:][:punct:]])+$/
static public boolean matchTitle(String title, String title2) {
Scanner scanner1 = new Scanner(title);
Scanner scanner2 = new Scanner(title2);
String searchTitle = title2;
boolean match = false;
int i = 0;
while(i < 2){
if(i == 1){
scanner1 = new Scanner(title2);
scanner2 = new Scanner(title);
searchTitle = title;
}
// breaks into words
while (scanner1.hasNext()){
match = false;
String token = scanner1.next();
scanner2 = new Scanner(searchTitle);
while (scanner2.hasNext() && !match){
String token2 = scanner2.next();
if(token.equals(token2)){
// if the words match
match = true;
}
}
if(!match){ // we have a word that didn't match any words in the second title
return false;
}
}
i++;
}
return true;
}
例
("similar words here", "similar words here") // true
("ここに似た言葉", "ここに似た言葉") // true
("similar words here", "similar words here different") // false