I saw the phrase
^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])[A-Za-z0-9_#@%\\*\\-]{8,24}$
in regex, which was password checking mechanism. I read few cou
(?=regex_here)
is a positive lookahead. It is a zero-width assertion, meaning that it matches a location that is followed by the regex contained within (?=
and )
. To quote from the linked page:
lookaround actually matches characters, but then gives up the match, returning only the result: match or no match. That is why they are called "assertions". They do not consume characters in the string, but only assert whether a match is possible or not. Lookaround allows you to create regular expressions that are impossible to create without them, or that would get very longwinded without them.
The .
is not part of the lookahead, because it matches any single character that is not a line terminator.