JSFiddle - React, Tailwind, and code Playground

by 2Yootz

JavaScript

var linkRegex = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(:[0-9]+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/;

var text = 'before http://google.com:5050 after';


   while ((match = linkRegex.exec(text))) {
      matchedUri = match[1] || match[2];
      console.log(matchedUri);
      break;
   }