generate functionThu, 08 Dec 2022

detect youtube link in text and replace it with embed

function getVideo(text) { var ytlink = /(?:youtu\.be\/|youtube\.com(?:\/embed\/|\/v\/|\/watch\?v=|\/user\/\S+|\/ytscreeningroom\?v=|\/sandalsResorts#\w\/\w\/.*\/))([^\/&]{10,12})/; var video = ytlink.exec(text); if (video) { return video[1]; } else { return false; } }

Javascript
Generate More

Questions about programming?Chat with your personal AI assistant