generate functionThu, 08 Dec 2022

detect youtube link in text and replace it with embed

function embedYoutubeLink(text){ var regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/; var match = text.match(regExp); if (match && match[2].length == 11) { return '<iframe src="https://www.youtube.com/embed/' + match[2] + '" frameborder="0" allowfullscreen></iframe>'; } else { return text; } }

Javascript
Generate More

Questions about programming?Chat with your personal AI assistant