regex pattern - what is ((?=.*\d)|(?=.*\W+)) and (?![.\n])
regex
Solution
These are all lookahead assertions (positive and negative) that are making sure the following text respects some rules without actually capturing the text.
# assert that
(?=^.{8,}$) # there are at least 8 characters
( # and
(?=.*\d) # there is at least a digit
| # or
(?=.*\W+) # there is one or more "non word" characters (\W is equivalent to [^a-zA-Z0-9_])
) # and
(?![.\n]) # there is no . or newline and
(?=.*[A-Z]) # there is at least an upper case letter and
(?=.*[a-z]).*$ # there is at least a lower case letter
.*$ # in a string of any characters
`(?! ... )` is the syntax for a negative lookahead (match if there is no ...), `(?= ... )` is for a positive lookahead (match if there is ...). This looks a lot like password validation!
Problem
can someone kindly explain this regex pattern to me? under ``` (?=^.{8,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$ ``` what exactly is ``` ((?=.*\d)|(?=.*\W+)) ``` & ``` (?![.\n]) ``` thank you