I have a regular expression:
l:([0-9]+)
This should match this string and return three captures (according to Rubular)
"l:32, l:98, l:234"
Here is my code:
Pattern p ...
Matcher m = p.matcher(...);
m.find();
System.out.println(m.groupCount());
This prints out 1 (group) when there are three, so I can only do m.group(1) which will only return 32.
Calling
Matcher.findfinds the next instance of the match, or returns false if there are no more. Try calling it three times and see if you have all your expected groups.To clarify,
m.group(1)is trying to find the first group expression in your regular expression. You only have one such group expression in your regex, sogroup(2)would never make sense. You probably need to callm.find()in a loop until it returns false, grabbing the group result at each iteration.