I want to write a code to justice the correctness of the password, but now the minus sign always turn error. I want to know the reason,even I have used the escape character.
String regEx = "[!@#$%^&*()\- ]";//this line
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(password);
specialCharFlag=m.find();
CodePudding user response:
他不是-的问题是\的问题\需要转义,所以你应该用\\
He is not - the problem is that \ problem \ needs to be escaped, so you should use \\
like this
String regEx = "[!@#$%^&*()\\- ]"; //this add a \