static String toRegularExpression(String glob) {
        StringBuilder output = new StringBuilder("^");
        boolean literal = true;
        boolean processingGroup = false;

        for (int i = 0; i < glob.length(); ) {
            char c = glob.charAt(i++);
            switch (c) {
                case '?':
                    literal = false;
                    output.append(".");
                    break;
                case '*':
                    literal = false;
                    output.append(".*");
                    break;
                case '\\':
                    if (i == glob.length()) {
                        output.append(c);
                    } else {
                        char next = glob.charAt(i);
                        i++;
                        if (isGlobSpecialCharacter(next) ||
                                isRegularExpressionSpecialCharacter(next)) {
                            output.append('\\');
                        }
                        output.append(next);
                    }
                    break;
                case '{':
                    if (processingGroup) {
                        throw new RuntimeException("Can't nest glob groups.");
                    }
                    literal = false;
                    output.append("(?:(?:");
                    processingGroup = true;
                    break;
                case ',':
                    if (processingGroup) {
                        literal = false;
                        output.append(")|(?:");
                    } else {
                        output.append(c);
                    }
                    break;
                case '}':
                    if (processingGroup) {
                        literal = false;
                        output.append("))");
                        processingGroup = false;
                    } else {
                        output.append(c);
                    }
                    break;
                // TODO: handle character ranges
                default:
                    if (isRegularExpressionSpecialCharacter(c)) {
                        output.append('\\');
                    }
                    output.append(c);
            }
        }
        if (processingGroup) {
            throw new RuntimeException("Unterminated glob group.");
        }
        if (literal) {
            return null;
        }
        output.append('$');
        return output.toString();
    }
Converts a glob string to a regular expression string.
Returns null if the glob should be handled as a literal (can only match one string).
Throws an exception if the glob is malformed.
shell/src/main/java/org/apache/kafka/shell/glob/GlobComponent.java