import re
regex = re.compile(r"([[:alnum:]-]+\.(?>de|com|net|org))\b", flags=re.MULTILINE)
test_str = ("||p5.focus.de/img/fotos/*/banner*.jpg$image\n"
"||apis.google.com/js/plusone.js$script\n"
"||mobilbranche.de/wp-content/themes/mobilbranche_2014/lib/img/mobilbranche_bg1.gif$image\n"
"||connect.facebook.net^$script\n"
"||a.bf-tools.net^$script\n"
"www1.wdr.de##.socialMedia\n"
"praxistipps.focus.de##.fb-wrap.fb-direction-row.fb-col-12")
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