$re = '/\b(?=(?:[a-z0-9]*[A-Z]){4})(?=(?:[A-Z0-9]*[a-z]){2})(?=[a-zA-Z]*[0-9])[A-Za-z0-9]{5,30}\b/m';
$str = 'https://stackoverflow.com/Abcde3FGhiDE/Zyx23 should match: Abcde3FGhiDE
|a|b|c|AbcdEFGH123|456Ac should match: AbcdEFG123
P A Abcde3FGhiDE Z H should match: Abcde3FGhiDE
ZZ123!Abcde3FGhiDE!123 should match: Abcde3FGhiDE
<HeLLoWoRlD"123
|A|b|c|D|E|F|1|
NULLLLLLLLLLLLLLLLLLLLLLllll 1
IAMoverTHELIMITTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT3';
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