static String replaceParameters(String format,
                                    String[] params) throws BadFormatString {
        Matcher match = PARAMETER_PATTERN.matcher(format);
        int start = 0;
        StringBuilder result = new StringBuilder();
        while (start < format.length() && match.find(start)) {
            result.append(match.group(1));
            String paramNum = match.group(3);
            if (paramNum != null) {
                try {
                    int num = Integer.parseInt(paramNum);
                    if (num < 0 || num >= params.length) {
                        throw new BadFormatString("index " + num + " from " + format +
                                " is outside of the valid range 0 to " +
                                (params.length - 1));
                    }
                    result.append(params[num]);
                } catch (NumberFormatException nfe) {
                    throw new BadFormatString("bad format in username mapping in " +
                            paramNum, nfe);
                }

            }
            start = match.end();
        }
        return result.toString();
    }
Replace the numbered parameters of the form $n where n is from 0 to
the length of params - 1. Normal text is copied directly and $n is replaced
by the corresponding parameter.
@param format the string to replace parameters again
@param params the list of parameters
@return the generated string with the parameter references replaced.
@throws BadFormatString
clients/src/main/java/org/apache/kafka/common/security/kerberos/KerberosRule.java