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

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

android - ConstraintLayout: Realign baseline constraint in case if dependent view visibility was set to GONE -

c# - Populating Gridview inside Listview ItemTemplate On Web User Control from Code Behind -