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

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -