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.
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
Post a Comment