我如何在比赛后抓住第一个单词?
例如,一旦我找到Car
,我该如何抓住Chevy
?
public class NewExtractDemo {
public static void main(String[] args) {
String input = "I have the following Car: Chevy, Truck: Ford, Van: Honda";
Pattern p = Pattern.compile("(Car|Truck|Van)");
Matcher m = p.matcher(input);
List<String> Search = new ArrayList<String>();
while (m.find()) {
System.out.println("Found a " + m.group() + ".");
Search.add(m.group());
}
}
}