获取与正则表达式匹配的所有字符串数组

8

我应该如何解析这样的文件:

Item costs $15 and is made up of --Metal--
Item costs $64 and is made up of --Plastic--

我能做到。
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(input);
String result = m.group();

但是如何获得每一个结果?
1个回答

12
Pattern p = Pattern.compile(regex); 
Matcher m = p.matcher(input);
List<String> matches = new ArrayList<String>();
while(m.find()){
    matches.add(m.group());
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接