JSFiddle - React, Tailwind, and code Playground
by Tiago Sousa
HTML
<form id="myform">
<textarea id="mytextarea"></textarea>
</form>
<button id="btnAction" onclick="myFunction()">Try It</button>
<div id="output"></div>
CSS
#output {
margin: 20px 0px;
}
#mytextarea {
width: 100%;
height: 250px;
}
JavaScript
function myFunction() {
var text = document.getElementById("mytextarea").value;
var extractedLinks = text.match(/(((https?:\/\/)|(www\.))[^\s]+)/g);
var outputElem = document.getElementById("output");
outputElem.innerText = extractedLinks[0];
}