我如何解析这样的文件:
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();
但我怎样才能得到每一个结果?
答案 0 :(得分:12)
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(input);
List<String> matches = new ArrayList<String>();
while(m.find()){
matches.add(m.group());
}