You do not need a regular expression for this:
var videoid = url.split('v=')[1]; var ampersandPosition = videoid.indexOf('&'); if(ampersandPosition != -1) { videoid = video_id.substring(0, ampersandPosition); }
You can use it if you want:
var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
Joren source share