$re = '/^(?=[^a-z]*[a-z])(?=[^A-Z]*[A-Z])(?=\D*\d)(?=[^!#%]*[!#%])[A-Za-z0-9!#%]{8,32}$/m';
$str = 'Must include at least 1 lower-case letter.
Must include at least 1 upper-case letter.
Must include at least 1 number.
Must include at least 1 special character (only the following special characters are allowed: !#%).
Is only allowed to include A-Za-z0-9!#% (no other characters are allowed).
Must be from 8 to 32 characters long.
Happyness1!';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php