JSFiddle - React, Tailwind, and code Playground

HTML

https://www.youtube.com/watch?v=mJirA9Hk8FY
https://vimeo.com/89203931

<textarea rows="4" cols="50">
    http://www.youtube.com/watch?v=mJirA9Hk8FY
        
    https://vimeo.com/89203931
        
</textarea>

JavaScript

var videoEmbed = {
    invoke: function(){
        
        $('body').html(function(i, html) {
            return videoEmbed.convertVideo(html);
        });
        
    },
    convertVideo: function(html){
        var pattern1 = /(?:http?s?:\/\/)?(?:www\.)?(?:vimeo\.com)\/?(.+)/g;
        var pattern2 = /(?:http?s?:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=)?(.+)/g;
        
        if(pattern1.test(html)){
            console.log("html", html);
            
           var replacement = '<iframe width="420" height="345" src="//player.vimeo.com/video/$1" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>';
           
           var html = html.replace(pattern1, replacement);
        }
           
        
        if(pattern2.test(html)){
              console.log("html", html);
            
           var replacement = '<iframe width="420" height="345" src="http://www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>';
            
            var html = html.replace(pattern2, replacement);
        } 
        
        
        return html;
    }
}






setTimeout(function(){
    videoEmbed.invoke();
},3000);