3v4l.org

run code in 300+ PHP versions simultaneously
<?php function matchStrings($str) { $ret = array(); // $ret = explode("\n", $str); foreach($ret as $asub) { $asub = str_replace('x', '', $asub); preg_match('/^(sh[0-9]+sh)+/', trim($asub), $ret['matches'][]); } $ret = array_unique($ret['matches']); foreach($ret as $sfind) { var_dump($sfind); } return $ret; // } $test = <<<MULTI xx xx sh1sh xx xx xx sh2sh xx xx xx xx sh**sh xx xx x xx xx sh3xxxsh xx xx sh4shsh5sh xxx MULTI; $matches = matchStrings($test); print_r($matches);

preferences:
45.73 ms | 402 KiB | 5 Q