/ Published in: JavaScript
This snippets show how to extract the video id of a youtube video from its URL
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=)([^#\&\?]*).*/; var match = url.match(regExp); if (match&&match[2].length==11){ return match[2]; }else{ //error }
URL: http://stackoverflow.com/questions/3452546/javascript-regex-how-to-get-youtube-video-id-from-url