JSFiddle - React, Tailwind, and code Playground

by sujesharukil

HTML

<textarea id="message">
    www.google.com ssdfsdfasdfasdf http://someplace.com?x=sdfsdf
</textarea>
<button type="button">Parse</button>

JavaScript

$(function(){
    
    $('button').click(function(){
        var $textarea = $('textarea'),
            message = $textarea.val(),
            urls = [],
            regex = new RegExp(/(^|\s)((https?:\/\/)?[\w-]+(\.[\w-]+)+\.?(:\d+)?(\/\S*)?)/gi);
        
        while (match = regex.exec(message)) {
            urls.push(match[0]);
       }
        
        console.log(urls); 
       
    });

});