I am using this code to loop through a Matcher and then add each match to a list. For some reason, the find() method is only finding the first 2 out of the 4 matches. I know that the pattern works because I have successfully matched all 4 items using an external regex tester.
Matcher NightQuantities = Pattern.compile('(?mi)(\\d)(?=\\sNight)').matcher(RatesDatesMatcher.group(1));
Integer x = 0;
while (NightQuantities.find()) //Adds number of nights for each period into list
{
NightQuantitiesList.add(Integer.valueOf(NightQuantities.group(x)));
System.debug('List input =' + NightQuantities.group(x));
System.debug('x = ' + x);
x++;
}
I keep getting the error:
"Group index out of bounds (parameter 1): No group 2