detect youtube link in text and replace it with embed
function youtube(text) { var regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/; var match = text.match(regExp); if (match && match[2].length == 11) { return '<iframe width="560" height="315" src="https://www.youtube.com/embed/' + match[2] + '" frameborder="0" allowfullscreen></iframe>'; } else { return text; } }