import re
regex = re.compile(r"(?<tag>\w+)\s?=\s?(?<code>.*$)", flags=re.MULTILINE)
test_str = ("[abilities]\n"
"UnknownDescTech0 = This ability does not seem to have any purpose.\n"
"UnknownName= ??? Ability\n"
"UnknownDescFun0 = No description\n"
"OneHitDeathName = 1-Hit Hero Badge\n"
"OneHitDeathDesc0 = You die in one hit. Only for the brave!\n\n"
"AddElement = Test Text.\n\n"
"[spaceship]\n\n"
"SuckInOrbsName = Item Magnet Badge\n"
"SuckInOrbsFun0 = Item just out of reach? No longer a problem!\n"
"SuckInOrbsTech0 = Automatically attract nearby collectibles!\"\n\n"
"[test]\n"
"hub_alert_generic0 = …[trophy]hub_alert_generic1 = [icon:trophy][trophy]今年度鳥映画アワード[/trophy]は内部の者によって不正に染まっていた。\n\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