Posted By

slimITTN on 02/11/13


Tagged

url video id YouTube


Versions (?)

Youtube ID from URL


 / Published in: JavaScript
 

URL: http://stackoverflow.com/questions/3452546/javascript-regex-how-to-get-youtube-video-id-from-url

This snippets show how to extract the video id of a youtube video from its URL

  1. var regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=)([^#\&\?]*).*/;
  2. var match = url.match(regExp);
  3. if (match&&match[2].length==11){
  4. return match[2];
  5. }else{
  6. //error
  7. }

Report this snippet  

You need to login to post a comment.