Q:

Two preg_match functions, whats the difference

Would someone to kind enough to explain to me what the difference (if any) between the two functions below is? I have been using the first for quite sometime to validate passwords. having done a little reading my head is now telling me the second function does exactly the same thing?
preg_match("/^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]).{6,}$/", $string);

Rewritten:
preg_match("/[a-zA-Z0-9]{6,}/", $string);

Any explanation is appreciated.

A:

/^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]).{6,}$/ - 6 characters, containing at least one digit, uppercase, and lowercase
/[a-zA-Z0-9]{6,}/ - a substring of 6 or more characters, which must be uppercase, lowercase, or digits

aA1___ is matched only by the first
111111 is matched only by the second

Note that enforcing stronger rules can result in weaker passwords - xkcd

