$re = '/((?<=\/|=)wall|photo|video)(-?[0-9]*)_([0-9]*)(\?reply=)?((?<=reply=)[0-9]*)?/';
$str = 'vk.com
https://vk.com/wall-67185996_74433
https://vk.com/video?z=video-175923038_456239401%2Fpl_cat_trends
https://vk.com/okoneshdmitriy?z=photo362009308_457249223%2Fwall362009308_754
https://vk.com/wall362009308_716
https://vk.com/wall-154906069_1311481?reply=1311486
https://vk.com/okoneshdmitriy?z=photo362009308_457248991%2Fphotos362009308
https://vk.com/wall362009308_742?reply=743';
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