private static String convertGlobToRegex(String pattern) {
        StringBuilder sb = new StringBuilder(pattern.length());
        AtomicInteger inGroup = new AtomicInteger(0);
        AtomicInteger inClass = new AtomicInteger(0);
        AtomicInteger firstIndexInClass = new AtomicInteger(-1);
        char[] arr = pattern.toCharArray();
        for (AtomicInteger index = new AtomicInteger(0); index.get() < arr.length; index.incrementAndGet()) {
            char ch = arr[index.get()];
            switch (ch) {
            case ESCAPE_CHAR:
                handleEscapeChar(sb, arr, index.incrementAndGet());
                break;
            case ASTERISK_CHAR:
                handleAsteriskChar(sb, inClass, arr, index);
                break;
            case QUESTION_MARK_CHAR:
                handleQuestionMarkChar(sb, inClass);
                break;
            case '[':
                handleOpeningBracketChar(sb, inClass, firstIndexInClass, index);
                break;
            case ']':
                handleClosingBracketChar(sb, inClass);
                break;
            case EXCLAMATION_SIGN_CHAR:
                handleExclamationSignChar(sb, firstIndexInClass, index);
                break;
            case '{':
                handleOpeningBraceChar(sb, inGroup);
                break;
            case '}':
                handleClosingBraceChar(sb, inGroup);
                break;
            case COMMA_CHAR:
                handleCommaChar(sb, inGroup);
                break;
            default:
                boolean shouldBeEscaped = IntStream.of(INPUT_CHARS_REQUIRING_ESCAPE).anyMatch(specialChar -> specialChar == ch)
                        && (inClass.get() == 0 || (ch == '^' && firstIndexInClass.get() == index.get()));
                if (shouldBeEscaped) {
                    sb.append(ESCAPE_CHAR);
                }
                sb.append(ch);
            }
        }
        return sb.toString();
    }
Converts a standard POSIX Shell globbing pattern into a regular expression pattern. The result can be used with the standard
{@link java.util.regex} API to recognize strings which match the glob pattern.

<p>
See also, the POSIX Shell language: http://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_13_01
</p>
Adapted from https://stackoverflow.com/a/17369948 with the difference that a single * is not interpreted as including slashes ("/").

@param pattern A glob pattern.
@return A regex pattern to recognize the given glob pattern.
jsonschema-maven-plugin/src/main/java/com/github/victools/jsonschema/plugin/maven/GlobHandler.java