private int getFailPosition(Pattern pattern, String input) {
        for (int i = 0; i <= input.length(); i++) {
            Matcher matcher = pattern.matcher(input.substring(0, i));
            if (!matcher.matches() && !matcher.hitEnd()) {
                return i - 1;
            }
        }
        return input.length();
    }