After extensive search, I am unable to find an explanation for the need to use .* in regex. For example, MSDN suggests a password regex of
@\\\"(?=.{6,})(?=(.*\\
.*
just means "0 or more of any character"
It's broken down into two parts:
.
- a "dot" indicates any character*
- means "0 or more instances of the preceding regex token"In your example above, this is important, since they want to force the password to contain a special character and a number, while still allowing all other characters. If you used \d
instead of .*
, for example, then that would restrict that portion of the regex to only match decimal characters (\d
is shorthand for [0-9]
, meaning any decimal). Similarly, \W
instead of .*\W
would cause that portion to only match non-word characters.
A good reference containing many of these tokens for .NET can be found on the MSDN here: Regular Expression Language - Quick Reference
Also, if you're really looking to delve into regex, take a look at http://www.regular-expressions.info/. While it can sometimes be difficult to find what you're looking for on that site, it's one of the most complete and begginner-friendly regex references I've seen online.