3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $regex = '/^http:\/\/([\w.]+)\/([\w]+)\/([\w]+)\.html$/i'; $str = 'http://www.youku.com/show_page/id_ABCDEFG.html'; $matches = array (); if (preg_match ( $regex, $str, $matches )) { var_dump ( $matches ); } echo "\n"; $regex = '#^http://([\w.]+)/([\w]+)/([\w]+)\.html$#i'; $str = 'http://www.youku.com/show_page/id_ABCDEFG.html'; $matches = array (); if (preg_match ( $regex, $str, $matches )) { var_dump ( $matches ); } echo "\n"; $regex = '/^[\d]{5,}$/i'; $str = '324546'; $matches = array (); if (preg_match ( $regex, $str, $matches )) { var_dump ( $matches ); } echo "\n"; if(preg_match("/php/i", "PHP is the web scripting language of choice.", $matches)){ print "A match was found:". $matches[0]; var_dump($matches); } else { print "A match was not found."; } $regex = '/HELLO/'; $str = 'hello word'; $matches = array(); if(preg_match($regex, $str, $matches)){ echo 'No i:Valid Successful!',"\n"; } if(preg_match($regex.'i', $str, $matches)){ echo 'YES i:Valid Successful!',"\n"; } $regex = '/HE(?=L)LO/i'; $str = 'HELLO'; $matches = array(); if(preg_match($regex, $str, $matches)){ var_dump($matches); } echo "\n"; $regex = '/HE(?=L)LLO/i'; $str = 'HELLO'; $matches = array(); if(preg_match($regex, $str, $matches)){ var_dump($matches); } echo "\n"; $regex = '/^(Chuanshanjia)[\w\s]+$/'; $regex2='/^(Chuanshanjia)([\w]|[\s])+$/'; $str = 'Chuanshanjia thank Chuanshanjia'; $matches = array(); if(preg_match($regex2, $str, $matches)){ var_dump($matches); } echo "\n"; ?>
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(4) { [0]=> string(46) "http://www.youku.com/show_page/id_ABCDEFG.html" [1]=> string(13) "www.youku.com" [2]=> string(9) "show_page" [3]=> string(10) "id_ABCDEFG" } array(4) { [0]=> string(46) "http://www.youku.com/show_page/id_ABCDEFG.html" [1]=> string(13) "www.youku.com" [2]=> string(9) "show_page" [3]=> string(10) "id_ABCDEFG" } array(1) { [0]=> string(6) "324546" } A match was found:PHParray(1) { [0]=> string(3) "PHP" } YES i:Valid Successful! array(1) { [0]=> string(5) "HELLO" } array(3) { [0]=> string(31) "Chuanshanjia thank Chuanshanjia" [1]=> string(12) "Chuanshanjia" [2]=> string(1) "a" }