-1

I have looked on ways like .split() to seperate strings and saw a simple seperation like .split(""), or .split("") but i don't know how to do more complex like remove everything before and after the id. What i have is a variable that contains a youtube string example:

var utubeLink = "http://img.youtube.com/vi/8lmuuaI09ro/0.jpg";

and a variable that is waiting to store the ID of the var utubeLink

var newutubeLink = "http://www.youtube.com/v/"

I want to remove everything so that i get 8lmuuaI09ro, and pass the ID into newutubeLink so that my final result will be http://www.youtube.com/v/8lmuuaI09ro.

Thanks

Rasclatt
  • 12,498
  • 3
  • 25
  • 33
Devon
  • 159
  • 1
  • 2
  • 15
  • Lots of questions related to this: http://stackoverflow.com/questions/10591547/how-to-get-youtube-video-id-from-url, http://stackoverflow.com/questions/3452546/javascript-regex-how-to-get-youtube-video-id-from-url?lq=1 – Ross Joo Dec 09 '14 at 04:08

1 Answers1

0

Use something like this, if the patterns of the URL doesn't change.

var utubeLink = "http://img.youtube.com/vi/8lmuuaI09ro/0.jpg";
var newutubeLink = "http://www.youtube.com/v/";
var parts = utubeLink.split('/');
var link = newutubeLink + parts[4];
console.log(link);
Grainier
  • 1,634
  • 2
  • 17
  • 30