$re = '/(\/([0-9]+)?|([a-z]+)?\.jpg|jpeg|png|gif)/m';
$str = 'http://site234.com/folder/ar.txt
http://jtem.com/folder/s.zip
http://site.com/folder/ddr
http://sit23e1.ru/folder/eff.jpg
http://spbrecommender.com/folder/karo.gif
http://site.eu/folder/spb.pdf
http://site.com/folder/lego.jpeg
http://sir.fr/folder/some.jpg
http://site.com/folder/erro.exe
http://personel.com/folder/1.png';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php