import re
regex = re.compile(r"^(?i)(https?:\/\/)?(www\.)?facebook\.com\/group(s)?(\/?\/\d+)?(\/.*)?$", flags=re.MULTILINE)
test_str = ("Https://wWw.facebook.Com/GROUpS/2233223616820715\n"
"httpS://Www.FACEBOOk.cOm/grouP/2233223616820715/?hoisteD_section_header_type=recentLY_seen&multi_permalinks=2744661819010223\n"
"https://www.facebook.com/groups/ukrainianenglishclubrachk21312Y\n"
"https://www.facebook.com/groups/ukrainianenglishclubrachky/events/fd\n\n"
"Http://wWw.facebook.Com/GROUpS/hhGGGh/22332\n"
"http://Www.FACEBOOk.cOm/grouP/2233223616820715/?hoisteD_section_header_type=recentLY_seen&multi_permalinks=2744661819010223\n"
"httP://www.facebook.com/groups/ukrainianenglishclubrachk21312Y\n"
"http://www.facebook.com/groups/ukrainianenglishclubrachky/events/fd\n\n"
"wWw.facebook.Com/GROUpS/2233223616820715\n"
"Www.FACEBOOk.cOm/grouP/2233223616820715/?hoisteD_section_header_type=recentLY_seen&multi_permalinks=2744661819010223\n"
"www.facebook.com/groups/ukrainianenglishclubrachk21312Y\n"
"www.facebook.com/groups/ukrainianenglishclubrachky/events/fd\n\n"
"facebook.Com/GROUpS/2233223616820715\n"
"FACEBOOk.cOm/grouP/2233223616820715/?hoisteD_section_header_type=recentLY_seen&multi_permalinks=2744661819010223\n"
"facebook.com/group/ukrainianenglishclubrachk21312Y\n"
"facebook.com/groups/ukrainianenglishclubrachky/events/fd")
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