Skip to content

Instantly share code, notes, and snippets.

@lelinhtinh
Created September 8, 2014 10:03
Show Gist options
  • Save lelinhtinh/fd52db9e9bacb9382fdd to your computer and use it in GitHub Desktop.
Save lelinhtinh/fd52db9e9bacb9382fdd to your computer and use it in GitHub Desktop.
Regex lấy id video youtube từ URL
// http://stackoverflow.com/a/8260383
function youtube_parser(url){
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
var match = url.match(regExp);
if (match&&match[7].length==11){
return match[7];
} else {
alert("Url incorrecta");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment