$array_num=array(); foreach($array_not as $v){ if(ereg("noticia([0-9]*).txt",$v,$out)){ $array_num[]=$out[1]; unset($out); }}