var url = 'https://vk.com/ID?z=photoID_ID%2FalbumID_0%2Frev'; var id = url.match(/z=([^&%]+)/); if(id){ id = id[1]; //... }