JSFiddle - React, Tailwind, and code Playground
HTML
<div class="messageText">
LOOK AT ME!!! youtube.com/watch?v=8tv-e9DJqK4 youtube.com/watch?v=8tv-e9DJqK4 youtube.com/watch?v=8tv-e9DJqK4
</div>
<div id="result"></div>
CSS
position: relative;width: 100%;height: 244px;padding-bottom: 34px;
JavaScript
$(document).ready(function(){
$('.messageText').html(function(i, html) {
address = html.replace(/(?:http:\/\/|https:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=)?(.*?)([^\s]+)/g, '<iframe src="http://www.youtube.com/embed/$2" frameborder="0" allowfullscreen id="videoPlayer" ></iframe>').replace(/(?:http:\/\/)?(?:www\.)?(?:vimeo\.com)\/(.+)/g, '<iframe id="videoPlayer" src="//player.vimeo.com/video/$1" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>');
//alert('iFrame is ' + address);
return address;
});
});