import re
regex = re.compile(r"https?:\/\/[^\/]+\.(?!com|fr|org\b)[a-zA-Z]{2,}", flags=re.MULTILINE)
test_str = ("va sur https://rcut.in/sa\n"
"https://izi.su/blabla\n"
"https://sn.ms/blabla\n"
"https://abn.ac/lol\n"
"https://fetuj.sk/mdr\n"
"https://cutl.top/1fHnl\n"
"https://www.google.fr\n"
"je suis pas un test\n"
"https://manger.fr\n"
"https://app.mobile.fr\n"
"https://www.hop.fyi/chPsF \n"
"www.google.com\n"
"https://voici.org\n"
"https://www.20minutes.fr/societe/4052202-20230909-choisi-avoir-chien-enfant-temoignage-veterinaire-helene-gateau \n"
"http://url.actualite.fr/89afe2c1\n")
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