[JS] Youtube Video ID URL Parser

Extract video id from youtube URL with javascript function
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]}
  var regExp2 = /^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/;
  var match2 = url.match(regExp2);
  if (match2 && match2[2].length == 11) {
    return match2[2];
  var regex = /(?:[?&]v=|\/embed\/|\/1\/|\/v\/|https?:\/\/(?:www\.)?youtu\.be\/)([^&\n?#]+)/gm;
  let m = regex.exec(url);
  if (m[1].length){
    return m[1];
  return url+' --failed--';
var n = [

See the Pen Youtube URL Parser by dimas lanjaka (@dimaslanjaka) on CodePen.

Subscribe to receive free email updates:

0 Response to "[JS] Youtube Video ID URL Parser"

Post a Comment

Bila Ada posting yang kurang, atau error atau yang lainnya, silahkan tinggalkan komentar agar artikel/post di perbaiki.
Jangan Lupa Cek Box "Notify Me" agar tahu komentar kamu dibalas oleh saya.

If there are any posts that are missing, or error or anything else, please leave a comment for the article / post to be fixed.
Do not Forget Check Box "Notify Me" to know our comments replied by me.