This will do the trick. Look ahead is nice for this...
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d.*\d)(?=.*\W.*\W)[a-zA-Z0-9\S]{4,}$/
**EXPLAINED in pieces below**
Look ahead/require for a lower case:
(?=.*[a-z])
Look ahead/require an uppercase:
(?=.*[A-Z])
Look ahead/require 2 digits:
(?=.*\d.*\d)
Look ahead/require any 2 non-word chars (same as [^a-zA_Z0-9_]):
(?=.*\W.*\W)
Entire password must contain a minimum of 4, a maximum is not defined, and only alpha numeric and special chars (non white-space):
[\S]{4,}
This will do the trick. Look ahead is nice for this...
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*\S)(?=.*[\S])[\S]{4,20}$/
**EXPLAINED in pieces below**
Look ahead/require for a lower case:
(?=.*[a-z])
Look ahead/require an uppercase:
(?=.*[A-Z])
Look ahead/require a digit:
(?=.*\d)
Look ahead/require any chars except white-space:
(?=.*[\S])
Entire password must contain a minimum of 4 and maximum of 20 only alpha numeric and special chars (non white-space):
[\S]{4,20}