import re
regex = re.compile(r"^(?<timestamp>\d+-\d+-\d+\s+\d+:\d+:\d+)\s+\[[^\]]*\]\s+\[(?<business_process_name>[^\]]*)\]\s+\[(?<business_process_step>[^\]]*)\]\s+\[(?<users>[^\]]*)\]\s+\w+\s+\[(?<error>[^\]]*)\]", flags=re.MULTILINE)
test_str = ("2021-09-28 10:20:27 [machine-run-76416-hit-644640-step-12470] [Business Process Name] [Business Process Step Name] [Bot Users] MetadataStorage [ERROR] Boot failed\n\n"
"2022-04-04 23:30:16 [http-nio-127.0.0.1-7080-exec-3] [] [] [] DataBaseChecker [DEBUG] Checking MySQL ...\n"
"2022-04-04 23:30:16 [http-nio-127.0.0.1-7080-exec-3] [] [] [] DatabaseVersionChecker [INFO] Database is up to date.\n"
"2022-04-04 23:30:16 [http-nio-127.0.0.1-7080-exec-3] [] [] [] DataBaseChecker [DEBUG] Checking PostgreSQL ...\n"
"2022-04-04 23:30:16 [http-nio-127.0.0.1-7080-exec-3] [] [] [] OcrHealthChecker [DEBUG] Checking OCR ...")
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