$re = '/^https?:\/\/(m\.)?vk\.com\/((club|public)(\d+)|[_.a-zA-Z0-9]{5,32})?(\?w=)?wall(-\d+)_(\d+)\??.*?&?.*?$/m';
$str = 'https://vk.com/club
https://vk.com/id
https://vk.com/id123
https://vk.com/club213560530
https://m.vk.com/club213560530
https://m.vk.com/club213560530
https://vk.com/wall-212141395_
https://vk.com/wall1_1
https://vk.com/ps4exploit?w=wall-212141395_852
https://vk.com/wall-212141395_852
https://vk.com/wall-110273246_191287?access_key=4d0bb719e17dc1433e
https://vk.com/wall-110273246_191287?access_key=
https://vk.com/wall-110273246_191287?foo
https://vk.com/wall-110273246_191287?
https://vk.com/wall-110273246_?access_key=4d0bb719e17dc1433e
https://vk.com/wall-110273246_191287?access_key=4d0bb719e17dc1433e&hello=world
https://vk.com/ps4exploit?w=wall-212141395_852&foo';
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