3v4l.org

run code in 300+ PHP versions simultaneously
<?php $pattern='/^(?=(.*[a-z])+)(?=(.*[A-Z]){2,})(?=(.*[0-9])+)(?=(.*[&#@=€$%*?\/:!\-+])+)([a-zA-Z0-9&#@=€$%*?\/:!\-+]){8,}$/'; echo "Using one byte from €:\\xe2 \\x82 \\xac", PHP_EOL; var_dump (preg_match($pattern, "aAB0\xe2ABC")); var_dump (preg_match($pattern, "aAB0\x82ABC")); var_dump (preg_match($pattern, "aAB0\xacABC")); echo "Avec €:", PHP_EOL; var_dump (preg_match($pattern, "aAB0€ABC")); echo PHP_EOL, "Since the regex engine reads the string byte by byte, the length of the string isn't what you expected.", PHP_EOL; var_dump(preg_match($pattern, "€aBC01")); ########################################################### echo PHP_EOL,PHP_EOL,'With the (*UTF8) verb',PHP_EOL,'###########################################################',PHP_EOL; $pattern='/(*UTF8)^(?=(.*[a-z])+)(?=(.*[A-Z]){2,})(?=(.*[0-9])+)(?=(.*[&#@=€$%*?\/:!\-+])+)([a-zA-Z0-9&#@=€$%*?\/:!\-+]){8,}$/'; echo "(*UTF8): Now € is seen as an character, no more as a set of bytes", PHP_EOL; var_dump (preg_match($pattern, "aAB0\xe2ABC")); var_dump (preg_match($pattern, "aAB0\x82ABC")); var_dump (preg_match($pattern, "aAB0\xacABC")); echo "Avec €:", PHP_EOL; var_dump (preg_match($pattern, "aAB0€ABC")); echo PHP_EOL, "Test with '€aBC01'. Now the regex engine reads the string unicode point by unicode point (encoded in UTF-8), the length of the string is the number of characters. Since there's less than 8 characters the pattern fails..", PHP_EOL; var_dump(preg_match($pattern, "€aBC01")); ########################################################### echo PHP_EOL,PHP_EOL, 'With the u modifier', PHP_EOL,'###########################################################',PHP_EOL; $pattern='/^(?=(.*[a-z])+)(?=(.*[A-Z]){2,})(?=(.*[0-9])+)(?=(.*[&#@=€$%*?\/:!\-+])+)([a-zA-Z0-9&#@=€$%*?\/:!\-+]){8,}$/u'; echo "The u modifier that is synonym of (*UTF8)(*UCP)", PHP_EOL; var_dump (preg_match($pattern, "aAB0\xe2ABC")); var_dump (preg_match($pattern, "aAB0\x82ABC")); var_dump (preg_match($pattern, "aAB0\xacABC")); echo "Avec €:", PHP_EOL; var_dump (preg_match($pattern, "aAB0€ABC")); echo PHP_EOL, "Test with '€aBC01'", PHP_EOL; var_dump(preg_match($pattern, "€aBC01"));

preferences:
33.77 ms | 402 KiB | 5 Q