Try this:
for(int i=1; i <= matcher.groupCount(); i++)
{
matchValue=matcher.group(i);
...
I am not sure why you would have a problem with the code you have, it seems to have exactly four groups, so for(int i=1; i<5;
seems correct. But it is better to have the matcher tell you what the count is.