public static String regexFormat(String regex) {
        if (regex == null) {
            throw new NullPointerException("regex string can't be null");
        }
        StringBuilder result = new StringBuilder();
        result.append('^');
        for (int i = 0; i < regex.length(); i++) {
            char ch = regex.charAt(i);
            if (isAsciiAlphanumeric(ch)) {
                result.append(ch);
            } else if (ch == '*') {
                result.append(".*");
            } else if (ch == QUESTION_MARK) {
                int j = 0;
                for (; j < regex.length() - i && ch == QUESTION_MARK; j++) {
                    ch = regex.charAt(i + j);
                }
                if (j == regex.length() - i) {
                    result.append(".{" + j + "}");
                    break;
                } else {
                    j -= 1;
                    result.append(".{" + (j) + "}");
                    i += j - 1;
                }
            } else {
                result.append("\\" + ch);
            }
        }
        result.append('$');
        return result.toString();
    }
@Test
    void testRegexFormat() {
        try {
            RegexParser.regexFormat(null);
            fail();
        } catch (NullPointerException e) {
            System.out.println(e.toString());
        }
        
        assertEquals("^test.*\\!.{1}xxxx$", RegexParser.regexFormat("test*!?xxxx"));
    }