Get ID from YouTube URL with JavaScript

A JavaScript function to extract the ID from a YouTube URL:

function getIdFromYoutubeURL(url) {
// regex from: https://stackoverflow.com/a/8260383/1492782
const regExp = /.*(?:youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=)([^#\&\?]*).*/;
const match = url.match(regExp);
return match && match[1].length == 11 ? match[1] : false;
};