code: public static List<String> regexGroups(Pattern regex, String str) {
      if (str == null) {
        return null;
      }
  
      Matcher matcher = regex.matcher(str);
      if (!matcher.find()) {
        return null;
      }
  
      List<String> groups = new ArrayList<String>();
      for (int index = 1; index <= matcher.groupCount(); index++) {
        groups.add(matcher.group(index));
      }
  
      return groups;
    }
docs: Given a pattern and a string, returns a list with the values of the
  captured groups in the pattern. If the pattern does not match, returns
  null. Note that this uses Matcher.find() rather than Matcher.matches().
  If str is null, returns null.