Can someone explain the meaning of these characters. I've looked them up but I don't seem to get it.
The whole regular expression is:
/^.*(?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%^&+=]).*$/
So basicly the start of the regex and the end characters.
The asterisk ( * ): The asterisk is known as a repeater symbol, meaning the preceding character can be found 0 or more times. For example, the regular expression ca*t will match the strings ct, cat, caat, caaat, etc.
. * therefore means an arbitrary string of arbitrary length. ^ indicates the beginning of the string. $ indicates the end of the string.
The Match-zero-or-more Operator ( * ) This operator repeats the smallest possible preceding regular expression as many times as necessary (including zero) to match the pattern. `*' represents this operator. For example, `o*' matches any string made up of zero or more `o' s.
The character * in a regular expression means "match the preceding character zero or many times". For example A* matches any number (including zero) of character 'A'. Regular Expression. Matches.
.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With