How to improve regex? -
How to improve regex? -
i need write regular look match characters: a-z a-z 0-9 .!$%&-_@#
without whitespace , in possible order knowledge of regular look lets closer 0 expert. , there need @ to the lowest degree 1 digit, 1 special character , 1 letter.
what able create on own:
[\s\w\.!$%&-_@#][^ ]{6,}
but i'm not sure it'll work assumed.
question:
how can create match entire word not part of it?
edit: i've tested , it's not meet that:
and there need @ to the lowest degree 1 digit, 1 special character , 1 letter.
examples:
not matching:
as1@.&%~+
asd dfgf
axf1345
1s4%z_-@#$ .!$%&-_@#
correct:
a1s#@%._
1acf3%&
abloct2$
@anubhava answer:
^(?=.*?[0-9])(?=.*?[a-za-z])(?=.*?[_.!$%&@#-])[\w.!$%&@#-]{6,}$
you can utilize lookahead based regex:
^(?=.*?[0-9])(?=.*?[a-za-z])(?=.*?[_.!$%&@#-])[\w.!$%&@#-]{6,}$
(?=.*?[0-9])
lookahead ensure there @ to the lowest degree 1 digit (?=.*?[a-za-z])
lookahead ensure there @ to the lowest degree 1 alphabet (?=.*?[.!$%&@#-])
lookahead ensure there @ to the lowest degree 1 special character regex demo regex
Comments
Post a Comment