JSFiddle - React, Tailwind, and code Playground

HTML

<h1>test results</h1>
<textarea id="results" style="width:100%;height:200px"></textarea>

JavaScript

var textarea = document.getElementById('results');

function assert(test, testName) {
    if (test) {
        textarea.value += testName + ': succeeded\r\n';
    } else {
        textarea.value += testName + ': failed\r\n';
    }
}

function parseYouTube(str) {
    // url : //youtube.com/watch?v=Bo_deCOd1HU
    // share : //youtu.be/Bo_deCOd1HU
    // embed : //youtube.com/embed/Bo_deCOd1HU
    
    var re = /\/\/(?:www\.)?youtu(?:\.be|be\.com)\/(?:watch\?v=|embed\/)?([a-z0-9_\-]+)/i; 
    var matches = re.exec(str);
    return matches && matches[1];
}

function parseVimeo(str) {
    // http://vimeo.com/86164897
    
    var re = /\/\/(?:www\.)?vimeo.com\/([0-9a-z\-_]+)/i;
    var matches = re.exec(str);
    return matches && matches[1];
}

assert(parseYouTube('<iframe width="420" height="315" src="//www.youtube.com/embed/BtXAmfgkGLI" frameborder="0" allowfullscreen></iframe>'),'youtube embed');
assert(parseYouTube('http://youtu.be/BtXAmfgkGLI'),'youtube share');
assert(parseYouTube('http://www.youtube.com/watch?v=BtXAmfgkGLI'),'youtube link');
assert(parseVimeo('<iframe src="//player.vimeo.com/video/86164897" width="500" height="264" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> <p><a href="http://vimeo.com/86164897">Focus: Portrait of a Runner - Sony F55</a> from <a href="http://vimeo.com/seanslobodan">Sean Michael</a> on <a href="https://vimeo.com">Vimeo</a>.</p>'),'vimeo iframe');
assert(parseVimeo('http://vimeo.com/86164897'),'vimeo link');