JSFiddle - React, Tailwind, and code Playground

by bvotcode

HTML

<div class="col_three_fifth">
<div>
<iframe width="560" height="315" src="https://www.youtube.com/embed/Xo4lTJc_c1c" title="YouTube video player?playsinline=1" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> </div>
<div class="row">
<div class="col-sm-12" style="padding-top:30px; text-align: center;">
<div class="addthis_inline_share_toolbox_u9ci"></div>
</div>
</div>
</div>

JavaScript

// Return all youtube links from text content
function youtubelinks() {
    // Initialize
    var results = [];
    // Loop through youtube regular expressions array
    $.each($(parent).find(children), function(index, value) {
        // Match elements containg youtube urls
        var match = $(this).text().match(/(http:|https:)?\/\/(www\.)?(youtube.com|youtu.be)\/(watch)?(\?v=)?(\S+)?/);
        if(match != null) {
            // Add matched URL to results
            results.push(match);
        }
    });
    // Return our links
    return results;
}
var html = '<div class="col_three_fifth">
<div>
<iframe width="560" height="315" src="https://www.youtube.com/embed/Xo4lTJc_c1c" title="YouTube video player?playsinline=1" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> </div>
<div class="row">
<div class="col-sm-12" style="padding-top:30px; text-align: center;">
<div class="addthis_inline_share_toolbox_u9ci"></div>
</div>
</div>
</div>'
// Get results example usage
var ytlinks = youtubelinks();
console.log(ytlinks)