开发者

Getting an array of every string that matches a Regular expression

开发者 https://www.devze.com 2023-02-09 03:27 出处:网络
How would I parse a file like this: Item costs $15 and is made up of --Metal-- I开发者_运维技巧tem costs $64 and is made up of --Plastic--

How would I parse a file like this:

Item costs $15 and is made up of --Metal--
I开发者_运维技巧tem costs $64 and is made up of --Plastic--

I can do

Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(input);
String result = m.group();

But how would I get EVERY result?


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

精彩评论

暂无评论...
验证码 换一张
取 消