import re
regex = re.compile((r"(?x)^\n"
r"([\d-]+)\s+([\d:.]+)\s+\n"
r"(\d+)\s\s(\d+)\s\n"
r"([VDIWEF])\s(.*?):\n"
r"(.*)\n"
r"$"), flags=re.MULTILINE)
test_str = ("06-09 17:48:08.555 1644 5345 V EXAPLE_TAG: hello I am a log1\n"
"06-09 17:48:08.555 1644 5345 D EXAPLE_TAG: hello I am a log2\n"
"06-09 17:48:08.555 1644 5345 I EXAPLE_TAG: hello I am a log3\n"
"06-09 17:48:08.555 1644 5345 W EXAPLE_TAG: hello I am a log4\n"
"06-09 17:48:08.555 1644 5345 E EXAPLE_TAG: hello I am a log5\n"
"06-09 17:48:08.555 1644 5345 F EXAPLE_TAG: hello I am a log6")
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