[英]Getting an array of every string that matches a Regular expression
我將如何解析這樣的文件:
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();
但是我將如何獲得每個結果?
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(input);
List<String> matches = new ArrayList<String>();
while(m.find()){
matches.add(m.group());
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.