Youtube ID from URL


/ Published in: JavaScript
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.