Java:获取与Regular表达式匹配的每个字符串的数组

Jos*_*fey 8 java regex arrays

我将如何解析这样的文件:

Item costs $15 and is made up of --Metal--
Item costs $64 and is made up of --Plastic--
Run Code Online (Sandbox Code Playgroud)

我可以

Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(input);
String result = m.group();
Run Code Online (Sandbox Code Playgroud)

但是我怎么能得到每一个结果呢?

Nis*_*ant 12

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