narayanpatra
narayanpatra

Reputation: 5691

regular-expression in java

I am using this regular expression in a java file to validate the password.

"^\w*(?=\w*\d)(?=\w*[a-z])(?=\w*[A-Z])\w*$"

It's showing the error :

Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ )

Can anybody tell me what mistake I am doing in this?(I don't know anything about regular expressions. I copied it from google.)

Upvotes: 1

Views: 166

Answers (1)

Mark Byers
Mark Byers

Reputation: 838256

In Java string literals you need to escape the backslashes.

"^\\w*(?=\\w*\\d)(?=\\w*[a-z])(?=\\w*[A-Z])\\w*$"

You can also simplify your regular expression by removing the first \\w* as it is not needed.

Upvotes: 7

Related Questions