java - String matches() method not working properly -


so have method:

   void verifysecretkey(string userenters, scanner input){      while(true) {         system.out.print("enter secret key:  ");         userenters = input.nextline();         system.out.println("\nverifying secret key...");          if (secretkey.matches(userenters)) {         system.out.println("secret key verified!");         break; }           else {         system.out.println("the secret key not follow proper format!"); }     } } 

and reason, not working properly. string secretkey automatically generated user , must enter exact string verified. however, if correct string entered, still says it's incorrect.

enter image description here

sometimes works, , doesn't. wondering doing wrong here?

string#matches accepts string defining regular expression. if want check equality, use equals, not matches.

"oh-?bt-4#" contains ?, special character in regular expressions, not literal ?. string doesn't match regular expression.


Comments

Popular posts from this blog

'hasOwnProperty' in javascript -

python - ValueError: No axis named 1 for object type <class 'pandas.core.series.Series'> -

java - How to provide dependency injections in Eclipse RCP 3.x? -