What are ^.* and .*$ in regular expressions?
.
means "any character".*
means "any number of this"..*
therefore means an arbitrary string of arbitrary length.^
indicates the beginning of the string.$
indicates the end of the string.
The regular expression says: There may be any number of characters between the expression (?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=])
and the beginning and end of the string that is searched.
^.* //Start of string followed by zero or more of any character (except line break)
.*$ //Zero or more of any character (except line break) followed by end of string
So when you see this...
(?=.*[@#$%^&+=]).*$
It allows any character (except line break) to come between (?=.*[@#$%^&+=])
and the end of the string.
To show that .
doesn't match any character, try this:
/./.test('\n'); is false
To actually match any character you need something more like [\s\S]
.
/[\s\S]/.test('\n') is true