Actually share the regulars, with which you can pull through the preg_match () user id (digits before the sign ) and video id (digits AFTER the mark ). Link to the video can be of two types: http://vk.com/video-39542227_162571485
http://vk.com/video39542227_162571485.
This is what I managed to write so far:

$str = '/(vk\.com|m\.vk\.com|)\/(video)()/i'; $res = preg_match($str, 'http://vk.com/video6596116_168597909', $match); 
  • Why is that? I just do not know the regulars. I can still write simple ones, but with more complicated the trouble begins. - makbeth

2 answers 2

 preg_match('/video([\d]+)_(\d+)/i', 'http://vk.com/video6596116_168597909', $matches) && print_r($matches); Array ( [0] => video6596116_168597909 [1] => 6596116 [2] => 168597909 ) 

So you can get the id for posts on the wall, videos and photos, and with the "-", if necessary:

 (?:wall|video|photo)?(.([\d]+)_(\d+)) 
  • And the point is there why? - Qwertiy
  • From the documentation Обратите внимание, идентификатор сообщества в параметре owner_id необходимо указывать со знаком "-" — например, owner_id=-1 соответствует идентификатору сообщества Without a dot, there will be no "-". Here is a great resource for writing regular expressions http://rubular.com/ - tab
  • I can write regulars. But why not there -? as well - because the point will also devour one digit, if there is no minus, and it is outside the group to be captured. - Qwertiy
  • Thanks for the advice. I tried (?:wall|video|photo)?(-?([\d]+)_(\d+)) and (?:wall|video|photo)?(.([\d]+)_(\d+)) for vk.com/videos-999?z=video-999_999 vk.com/videos-999?z=video999_999 work the same way. - tab
  • If the video does not belong to the community: https://vk.com/videos99999999?z=video99999999_999999999%2Fpl_99999999_-9 (in the real link I changed all the numbers to nine). - Qwertiy