final String regex = "^[A-Za-z0-9]{1,12}$";
final Pattern pattern = Pattern.compile(regex);
System.out.println(pattern.matcher("hi!").?);
Is there a way to get what went wrong with Matcher? In this case, "!" is not allowed, as you can see from regex. I'd like to have a result, something like "'!' is not allowed".