const regex = /^https?:\/\/(?:[^@\/\n]+@)?(?:www\.)?([^:\/\n]+)/igm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^https?:\\\/\\\/(?:[^@\\\/\\n]+@)?(?:www\\.)?([^:\\\/\\n]+)', 'igm')
const str = `random
123
www.co
http://calgarymayor.ca/
http://calgarymayor.ca/Disclosure%20docs/Expenses/Budget%20ending%202017-04-30.pdf
http://calgarymayor.ca/bio
http://citytalk.calgary.ca/
http://citytalk.calgary.ca/careers
http://www.calgaryarb.ca
http://www.calgaryarb.ca/eCourtPublic/15M2018.pdf
http://www.calgarymlc.ca/
http://www.calgarymlc.ca/about-cmlc/
http://www.calgarypolicecommission.ca/ *********
http://www.calgarypolicecommission.ca/reports.php *******
http://www.citiesmatter.ca/
https://attainyourhome.com/ ********
https://cityonline.calgary.ca/Pages/Cart.aspx ******
https://data.calgary.ca/
https://data.calgary.ca//api/views/24tg-us6q/rows.rss?accessType=DOWNLOAD
https://data.calgary.ca/Base-Maps/Alberta-Township-Sections/q6ds-xz2v/data
https://engage.calgary.ca/
https://liveandplay.calgary.ca/DROPIN/page/dropin *******
https://maps.calgary.ca
https://myid.calgary.ca/idm/`;
// 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