const str = "Visit https://en.wikipedia.org/ for more info."; str.replace(/\b(https?|ftp|file):\/\/\S+[\/\w]/g, '<a href="$&">$&</a>'); // => "Visit <a href="https://en.wikipedia.org/">https://en.wikipedia.org/</a> for more info."