3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function testRegExp($regexp, $string) { $valid = preg_match($regexp, $string); echo $string. " - " . ($valid ? "valid" : "invalid") ."\n"; } function matchRegExp($regexp, $text){ if(preg_match($regexp, $text, $matches)){ print_r($matches); }else{ echo "no match in text: ".$text; } echo "\n"; } // hledání emailu @seznam.cz v textu (zjednodušená verze) $regexpEmail = "/\b(?P<email>\w+@seznam\.cz)\b/"; matchRegExp($regexpEmail, "adsd dominik@seznam.cz ssdasd"); matchRegExp($regexpEmail, "adsd dominik@seam.cz ssdasd"); // validace IP adresy $regexpIp = "/^((25[0-5]|2[0-4]\d|[01]?\d?\d)\.){3}(25[0-5]|2[0-4]\d|[01]?\d?\d)$/"; echo "Test IP\n"; testRegExp($regexpIp, "10.1.0.1"); testRegExp($regexpIp, "199.1.0.1"); testRegExp($regexpIp, "255.1.0.1"); testRegExp($regexpIp, "256.1.0.1"); testRegExp($regexpIp, "260.1.0.1"); testRegExp($regexpIp, "300.1.0.1"); testRegExp($regexpIp, "1.0.1"); testRegExp($regexpIp, "125.1..1"); testRegExp($regexpIp, "192.11.168.255"); testRegExp($regexpIp, "192.11.168.256"); testRegExp($regexpIp, "192.11.168.300");
based on m16Ke
Output for 5.6.0 - 7.3.0alpha1
Array ( [0] => dominik@seznam.cz [email] => dominik@seznam.cz [1] => dominik@seznam.cz ) no match in text: adsd dominik@seam.cz ssdasd Test IP 10.1.0.1 - valid 199.1.0.1 - valid 255.1.0.1 - valid 256.1.0.1 - invalid 260.1.0.1 - invalid 300.1.0.1 - invalid 1.0.1 - invalid 125.1..1 - invalid 192.11.168.255 - valid 192.11.168.256 - invalid 192.11.168.300 - invalid