See my post here
Regex for at least 8 + upper and lower+numbers or other non-alphabetic
Suppose i just need this 2 condition below,
what should be the regular expression?
- Contains upper and lower case letters.
- Contains numbers or other non-alphabetic characters.
I tried ^(?=.*?[a-z])(?=.*?[A-Z])(?=.*?[^a-zA-Z])$
but not working
BUT just-
–(?=.*?[a-z])(?=.*?[A-Z])(?=.*?[^a-zA-Z]) is working
can i use just (?=.*?[a-z])(?=.*?[A-Z])(?=.*?[^a-zA-Z]) for the purpose?
The problem here is that the look ahead/behind are zero-width, “non-consuming”. That means your
will never match because the lookarounds consumed nothing and whats then left? only
^$that would match an empty string, but this does not meet your lookahead criterias.So you should use
that
.*will consume everything and the look aheads ensure the criterias.you can also define a length replacing the
*with{x,}where x is the minimum amount of characters of the string