I have a line from which multiple keywords are to be matched. The whole keywords should be matched.
Example,
String str = "This is an example text for matching countries like Australia India England";
if(str.contains("Australia") ||
str.contains("India") ||
str.contains("England")){
System.out.println("Matches");
}else{
System.out.println("Does not match");
}
This code works fine. But if there are too many keywords to be matched, the line grows. Is there any elegant way of writing the same code?
Thanks
Your can write a regular expression like this:
Use it like this:
If you would like to know which countries has matched:
Outputs: