JSFiddle - React, Tailwind, and code Playground

by khushboo097

JavaScript

replacePattern1 = /(?!([^<]+)>)(?:https?:\/\/)(?:[\da-z-]+\.)+[a-z]{2,10}(?:\/[^\s/]+)*\/?\w(?=<|\s|$)/gim;
 var replacedText = "https://google.com https://abc.com"
 
/*  var linksWithoutTagsMatches = replacePattern1.exec(replacedText); */
var test = replacedText
while ((linksWithoutTagsMatches = replacePattern1.exec(test)) !== null) {
 console.log(linksWithoutTagsMatches[0]);
 replacedText = replacedText.replace(replacePattern1, '<a href="'+linksWithoutTagsMatches[0]+'" target="_blank">'+linksWithoutTagsMatches[0]+'</a>');
 }