Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我有以下代码:
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()); }
是否有可能知道找到了“菲亚特”、“熊猫”或“福特”中的哪个关键字?
This should do it. You had p1.matcher, instead you need to change it to p.matcher.
p1
p
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()); }