private String getGroupsOutput(Pattern pattern, String testStr) {
    String result = "";
    Matcher matcher = pattern.matcher(testStr);
    if(matcher.find()) {
      for(int i=0; i <= matcher.groupCount(); i++) {
        int startIndex = matcher.start(i);
        int endIndex = matcher.end(i);
        String groupString = "undefined";
        if(startIndex != -1) {
          groupString = testStr.substring(startIndex, endIndex);
        }
        result += "Group " + i + ": (" + groupString + ")\n";
      }
    }
    return result;
  }