Skip to content

Instantly share code, notes, and snippets.

View deunlee's full-sized avatar
🙃
Mood-Driven-Development!

Deun Lee deunlee

🙃
Mood-Driven-Development!
View GitHub Profile
@deunlee
deunlee / YouTube_Video_ID_By_URL.js
Last active October 20, 2022 12:56
Get YouTube Video ID by URL (+ URL examples)
function getYouTubeVideoIdByUrl(url) {
const reg = /^(https?:)?(\/\/)?((www\.|m\.)?youtube(-nocookie)?\.com\/((watch)?\?(feature=\w*&)?vi?=|embed\/|vi?\/|e\/)|youtu.be\/)([\w\-]{10,20})/i
const match = url.match(reg);
if (match) {
return match[9];
} else {
return null;
}
}