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

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -