Can you help me in finding a regex that take list of phrases and check if one of these phrases exist in the given text, please?
Example:
If I have in the hashSet
the following words:
??? ?????
??? ???
??? ????
?? ?? ??? ???
And the given text is: ??? ????? ????? ?? ???? ????
I want to get after performing regex: ??? ?????
My initial code:
HashSet<String> QWWords = new HashSet<String>();
QWWords.add("??? ?????");
QWWords.add("??? ???");
QWWords.add("??? ????");
QWWords.add("?? ?? ??? ???");
String s1 = "??? ????? ????? ?? ???? ????";
for (String qp : QWWords) {
Pattern p = Pattern.compile("[\s" + qp + "\s]");
Matcher m = p.matcher(s1);
String found = "";
while (m.find()) {
found = m.group();
System.out.println(found);
}
}
See Question&Answers more detail:os