Home > Blockchain >  Isn't the escape character a slash? Why I reported this error, I need to use two slashes to pas
Isn't the escape character a slash? Why I reported this error, I need to use two slashes to pas

Time:06-21

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 \

  • Related