const regex = /^http(s)?:\/\/([^\/]+)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^http(s)?:\\\/\\\/([^\\\/]+)', 'gm')
const str = `https://kdl.ru/patient/blog/omega-3-piti-ili-ne-piti
https://apteka-april.ru/blog/intresting-and-useful/37-chto-takoe-omega-3
https://galina-erikson.ru/poleznye-dlya-zdorovya-stati/a-vy-znaete-kak-pravilno-vybrat-preparat-omega-3
https://omega-labs.ru/
https://www.sportfood40.ru/articles/kak-vybrat-omega-3/
https://www.kp.ru/expert/elektronika/luchshie-noutbuki-dlya-raboty/
https://yandex.ru/video/preview/11052470352245519618?text=какой ноутбук купить для работы&path=yandex_search&parent-reqid=1678203470996582-5656932453459637239-sas3-0967-c7e-sas-l7-balancer-8080-BAL-6300&from_type=vast
https://www.OZON.ru/club/article/roboty-pylesosy-reyiting-modeleyi-dlya-chistoty-v-kvartire-16303710/
https://рейтинг-лучшего.рф/rejtingi/luchshie-detskie-smart-chasy/
https://mobilegadjet.ru/sravneniya/2340-`;
// 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