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 = /^.*(\/|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


RSS Icon Subscribe to comments

You need to login to post a comment.