Skip to content

Instantly share code, notes, and snippets.

@fredchu
Created June 27, 2014 17:07
Show Gist options
  • Save fredchu/5c780748c85d0d773291 to your computer and use it in GitHub Desktop.
Save fredchu/5c780748c85d0d773291 to your computer and use it in GitHub Desktop.
Regex for getting YouTube id from YouTube url
var _regex = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
var videoUrl = 'http://www.youtube.com/watch?v=D1GmL_mvmwY&feature=g-high-u';
// there you go~
var youtubeId = videoUrl.match(_regex)[7];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment