If you need to find the url's in a string and convert them to HTML link elements using JavaScript, feel free to take this handy regex expression:
1 2 3 4 5 6 7 8 9 10 11 12 |
function parseLinks(string) { const exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig return string.replace(exp,`<a href='$1'>$1</a>`) } console.log ( parseLinks('Follow this https://www.google.com') ); // Output: // Follow this <a href='https://www.google.com' target='_blank'>https://www.google.com</a>" |