Skip to content

Instantly share code, notes, and snippets.

@geraldotech
Created January 20, 2024 18:54
Show Gist options
  • Save geraldotech/9f68140ad7a725fcfa488ce1898cfa08 to your computer and use it in GitHub Desktop.
Save geraldotech/9f68140ad7a725fcfa488ce1898cfa08 to your computer and use it in GitHub Desktop.
getYoutubeVideoID.js
function getparams(url){
let regex = /[^=\]]+(?=&)/g;
// void broken code add a & final url
let str = url + '&';
let match = regex.exec(str)[0];
return match
}
console.log(getparams('https://www.youtube.com/watch?v=z_DNPipPdUA&t=1900s'))
console.log(getparams('https://www.youtube.com/watch?v=uzUoGD1G6LU&list=RDuzUoGD1G6LU&start_radio=1&rv=z_DNPipPdUA'))
console.log(getparams('https://www.youtube.com/watch?v=Et9llKBJdEs'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment