Reputation: 53
If I have the following code:
Pattern p = Pattern.compile("Fiat|Panda|Ford");
String searchStr = "Fiat Panda 4747 ";
Matcher m = p1.matcher(searchStr);
while(m.find()) {
System.out.println(m.group());
}
Is it possible to know which of the keywords "Fiat", "Panda" or "Ford" was found?
Upvotes: 1
Views: 61
Reputation: 70732
This should do it. You had p1
.matcher, instead you need to change it to p
.matcher.
String in = "Fiat Panda 4747";
Pattern p = Pattern.compile("Fiat|Panda|Ford");
Matcher m = p.matcher(in);
while (m.find()) {
System.out.println(m.group());
}
Upvotes: 1