private static Pattern toRegexPattern(String pattern, char[] boundaries, boolean enableSingleCharWildcard) {
        StringBuilder builder = new StringBuilder("^");
        StringBuilder precedingCharactersToQuote = new StringBuilder();
        char[] chars = pattern.toCharArray();
        for (char c : chars) {
            if ((enableSingleCharWildcard && c == '?') || c == '*') {
                builder.append(quotePrecedingLiteralsAndReset(precedingCharactersToQuote));
                // Note: we explicitly stop matching at a separator boundary.
                // This is to make matching less vulnerable to dirty tricks (e.g dot as boundary for hostnames).
                // Same applies for single chars; they should only match _within_ a boundary.
                builder.append("[^").append(Pattern.quote(new String(boundaries))).append("]");
                if (c == '*') builder.append('*');
            } else {
                precedingCharactersToQuote.append(c);
            }
        }
        return Pattern.compile(builder.append(quotePrecedingLiteralsAndReset(precedingCharactersToQuote)).append('$').toString());
    }
Matching engine for glob patterns having where one ore more alternative characters acts a boundary for wildcard matching.

@author bjorncs
security-utils/src/main/java/com/yahoo/security/tls/GlobPattern.java