generate functionTue, 13 Dec 2022

js replace all youtube urls in string with embed code

const youtubeEmbed = url => url.replace( /^.*(youtu\.be\/|v\/|u\/\w\/|embed\/|watch\?v=|&v=)([^#&?]*).*$/i, '<iframe width="560" height="315" src="https://www.youtube.com/embed/$2" frameborder="0" allowfullscreen></iframe>' ) youtubeEmbed('https://www.youtube.com/watch?v=I0FxANgd6wg') // <iframe width="560" height="315" src="https://www.youtube.com/embed/I0FxANgd6wg" frameborder="0" allowfullscreen></iframe>

Javascript
Generate More

Questions about programming?Chat with your personal AI assistant