Reputation: 612
These are the symbols should contain in !"#$%&'()*+-./:;<=>?@[\]^_
{|}~`
but i am trying to put " this special character it is giving error[compile time error]
private static final String PASSWORD_PATTERN = "((?=.*[a-z])(?=.*\\d)(?=.*[A-Z])(?=.*["@#$%!%^&*()_+=?/[],.<>|~`'-]).{8,32})";
Can an one hep , thanks in advance
Upvotes: 0
Views: 525
Reputation: 817
I recommend to use https://www.debuggex.com/ when you are trying to work with regular expressions. It's easier and directly tells you if your regex is incorrect.
Upvotes: 0
Reputation: 382394
Of course you can't simply put a quote in a string literal, that ends the string. And it's not related to regular expression, that would be the same whatever you do later with the string.
Simply escape it : replace "
with \"
Addendum regarding the new question in comments : if you put [
and ]
in a character class (that is between [
and ]
), then you must escape them for the regular expression. And as you do that in a string literal, that makes a double escaping because you must escape the \
. And you must also escape the -
in a character class.
So change
["@#$%!%^&*+=?/[],.<>|~`'-:/<>]
to
["@#$%!%^&*+=?/\\[\\],.<>|~`'\\-:/<>]
Upvotes: 3