const regex = /(http(s)?:\/\/.)?(www\.)?(?:[-a-zA-Z0-9@:%_\+~#=]{1,63}\.)+[a-z]{2,6}\b((?:[-a-zA-Z0-9@:%_\+~#?&//="]+\.)*[-a-zA-Z0-9@:%_\+~#?&//="]+)?/g;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(http(s)?:\\\/\\\/.)?(www\\.)?(?:[-a-zA-Z0-9@:%_\\+~#=]{1,63}\\.)+[a-z]{2,6}\\b((?:[-a-zA-Z0-9@:%_\\+~#?&\/\/="]+\\.)*[-a-zA-Z0-9@:%_\\+~#?&\/\/="]+)?', 'g')
const str = `asfd http://gskinner.co.im asfd
asfd m.skinner.com asfd
asfd www.gskinner.com asfd
asfd http://www.gskinner.com asfd
asfd www.gskinner.com?a=1&b=2 asfd
asfd gskinner.com?a="1"%203&b=2 asfd
asfd http://gskinner.com/a/b?c=3 asfd
asfd https://gskinner.com/a/b?c=3 asfd
asfd fdg.f.fg.gskinn.er.com/a/b?c=3 asfd
asfd ffgfgfgfgdfd/dfdfd.df asfd
asfd https://web.whatsapp.com/%F0%9F%8C%90/en asfd
asfd sdfsd://asdfw.asgd asfd
wealth.in..mutual sdf of 10k
wealth.Mutual,dfdfg sdf of 10k
wealth.Mutu/#index al of 10k
wealth.#MutualFundsSIP of 10k
wealth.\$MutualFundsSIP of 10k
`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
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