1

如果我有以下代码:

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());
}

是否有可能知道找到了“菲亚特”、“熊猫”或“福特”中的哪个关键字?

4

1 回答 1

1

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());
}
于 2013-10-07T17:06:47.377 回答