Reputation: 1849
I have urls which look like this :http://i1.ytimg.com/vi/BR0Y3MZ21bo/0.jpg
. Can someone help me extract the "ID" BR0Y3MZ21bo
between the last two slashes in the url?
Upvotes: 2
Views: 1695
Reputation: 74738
Try this:
var url = 'http://i1.ytimg.com/vi/BR0Y3MZ21bo/0.jpg'; // window.location.href;
var page = url.substr(0, url.lastIndexOf('/')); // output -> http://i1.ytimg.com/vi/BR0Y3MZ21bo
var str = page.substr(page.lastIndexOf('/')+1); // output -> BR0Y3MZ21bo
alert(str); // BR0Y3MZ21bo
Upvotes: 0