protected Pattern translateMaskIntoRegex(StringBuilder regex, String mask) {
        boolean optionalFound = false;
        boolean escapeFound = false;

        for (char c : mask.toCharArray()) {
            if (c == '[' || c == ']') {
                optionalFound = true;
            }
            else if (c == '\\') {
                escapeFound = true;
            }
            else {
                regex.append(translateMaskCharIntoRegex(c, optionalFound, escapeFound));
                escapeFound = false;
            }
        }
        return Pattern.compile(regex.toString());
    }
Translates a mask pattern into a regular expression pattern.

@param regex the StringBuilder to append the translated regular expression to.
@param mask the mask pattern to translate into a regular expression.
@return the translated regular expression as a {@link Pattern}.
primefaces/src/main/java/org/primefaces/component/inputmask/InputMaskRenderer.java