I want to find the occurrences of all the words in a ListArray comparing it with a String. So far, I am able to do it as a for loop, where I store all the possible combinations and run them using a matches i.e.
for(String temp_keywords: keywords){
final_keywords_list.add(" "+ temp_keywords+ " ");
final_keywords_list.add(" "+ temp_keywords+".");
final_keywords_list.add(" "+ temp_keywords+ ",");
final_keywords_list.add(" "+ temp_keywords+ "!");
final_keywords_list.add(" "+ temp_keywords+ "/");
final_keywords_list.add(" "+ temp_keywords+ "?");
}
for (String temp_keywords : final_keywords_list) {
String add_space = temp_keywords.toLowerCase();
p = Pattern.compile(add_space);
m = p.matcher(handler_string);
int count = 0;
while (m.find()) {
count += 1;
}
However, I want to remove the manual addition for the combinations and do a regex. I've seen examples of words with regex but how do I add a variable string to the regex? Sorry, I am a beginner java learner.