const regex = /(http\:|ftp\:|https\:)?(\/\/)?([\w_-]+(?:(?:\.[\w_-]+)+)[\w.,@?^=%&:\/~+#-()].*[\w@?^=%&\/~+#-]?)(?=\s|$)/img;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(http\\:|ftp\\:|https\\:)?(\\\/\\\/)?([\\w_-]+(?:(?:\\.[\\w_-]+)+)[\\w.,@?^=%&:\\\/~+#-()].*[\\w@?^=%&\\\/~+#-]?)(?=\\s|$)', 'img')
const str = `https://en.wikipedia.org/wiki/Salt_(2010_film)
https://en.wikipedia.org/wiki/Salt_2010_film
https://en.wikipedia.org/wiki/Salt-2010-film
HTTPS://en.wikipedia.org/wiki/Salt-2010-film
//en.wikipedia.org/wiki/Salt_2010_film
https://en.wikipedia.org/wiki/Salt_2010_film?cat=1
https://en.wikipedia.org/wiki/Salt_2010_film#anchor
https://en.wikipedia.org/wiki/Salt_(2010_film)?cat=2
This is a sentence that has a link in it. https://en.wikipedia.org/wiki/Salt_(2010_film)?cat=3 This regex allows me to create an HTML anchor tag around it.`;
const subst = `<a href="${1}${2}${3}" target="_blank">${1}${2}${3}</a>`;
// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);
console.log('Substitution result: ', result);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions