import re
regex = re.compile(r"(?<event>^.\S*[^\n<]*(?:(?:<(?!)|\n(?!$))[^\n]*)*(?:|\n$|\z))", flags=re.MULTILINE)
test_str = ("isDraggingObject : True\n"
"id : afbbdeb7-9fd4-4b53-ab17-742809154ba9\n"
"condition : {or, matches System.Object[] (?i)(^.*?host failure \n"
" alert.*?www\\.jennycraig\\.com\\.au.*?$), matches System.Object[] \n"
" (?i)(^.*?\\bwarning\\b.*?www\\.jennycraig\\.com\\.au.*?$)}\n"
"catch_all : False\n"
"advanced_condition : {}\n"
"actions : {route PVG22KK, severity warning}\n\n"
"isDraggingObject : True\n"
"id : 3b5aa785-b854-4e43-900a-225da5786a27\n"
"condition : {or, matches System.Object[] \n"
" (?i)(^.*?\\bcritical\\b.*?www\\.jennycraig\\.com\\.au.*?$)}\n"
"catch_all : False\n"
"advanced_condition : {}\n"
"actions : {severity critical, route PVG22KK}\n\n"
"**isDraggingObject : True\n"
"id : a8420998-fbca-486b-9ff7-d03b9e16536e\n"
"condition : {or, matches System.Object[] (?i)(^.*?\\bcritical\\b.*?www\\.jennycraig\\.com$), \n"
" matches System.Object[] (?i)(^.*?\\bcritical\\b.*?locations\\.jennycraig\\.com)}\n"
"catch_all : False\n"
"advanced_condition : {}\n"
"actions : {severity critical, route PW0VV83}**")
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