import re
regex = re.compile(r"^http(s)?:\/\/([^\/]+)", flags=re.MULTILINE)
test_str = ("https://kdl.ru/patient/blog/omega-3-piti-ili-ne-piti\n"
"https://apteka-april.ru/blog/intresting-and-useful/37-chto-takoe-omega-3\n"
"https://galina-erikson.ru/poleznye-dlya-zdorovya-stati/a-vy-znaete-kak-pravilno-vybrat-preparat-omega-3\n"
"https://omega-labs.ru/\n"
"https://www.sportfood40.ru/articles/kak-vybrat-omega-3/\n"
"https://www.kp.ru/expert/elektronika/luchshie-noutbuki-dlya-raboty/\n"
"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\n"
"https://www.OZON.ru/club/article/roboty-pylesosy-reyiting-modeleyi-dlya-chistoty-v-kvartire-16303710/\n"
"https://рейтинг-лучшего.рф/rejtingi/luchshie-detskie-smart-chasy/\n"
"https://mobilegadjet.ru/sravneniya/2340-")
matches = regex.finditer(test_str)
for match_num, match in enumerate(matches, start=1):
print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}")
for group_num, group in enumerate(match.groups(), start=1):
print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")
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 Python, please visit: https://docs.python.org/3/library/re.html