js replace all youtube urls in string with embed code
function youtubeReplace(str) { let regex = /http(?:s?):\/\/(?:www\.)?youtu(?:be\.com\/watch\?v=|\.be\/)([\w\-\_]*)(&(amp;)?[\w\?=]*)?/; let result = str.replace(regex, '<iframe width="560" height="315" src="https://www.youtube.com/embed/$1" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>'); return result; } youtubeReplace("https://www.youtube.com/watch?v=jNQXAC9IVRw")