import re
regex = re.compile(r"BEGIN:VEVENT.*?END:VEVENT", flags=re.MULTILINE | re.DOTALL)
test_str = ("BEGIN:VEVENT\n"
"DTSTAMP:20220301T023567Z\n"
"UID: xxx\n"
"DTSTART;TZID=Asia/Tokyo:20210630T110000\n"
"DTEND;TZID=Asia/Tokyo:20210630T160000\n"
"DESCRIPTION:\\n--------\\n同日入替 : false\\n前回ゲスト数 : 1\\n次\n"
"SUMMARY: xxxxx (xxx / xxx xxx\n"
"END:VEVENT\n"
"BEGIN:VEVENT\n"
"DTSTAMP:20221105T072143Z\n"
"UID: xxx\n"
"DTSTART;TZID=Asia/Tokyo:20210501T110000\n"
"DTEND;TZID=Asia/Tokyo:20210701T160000\n"
"DESCRIPTION:\\n--------\\n同日入替 : false\\n前回ゲスト数 : 1\\n次\n"
"SUMMARY: xxx (xxx / xxx xxx)\n"
"END:VEVENT\n"
"BEGIN:VEVENT\n"
"DTSTAMP:20220905T023143Z\n"
"UID: xxx\n"
"DTSTART;TZID=Asia/Tokyo:20220227T110000\n"
"DTEND;TZID=Asia/Tokyo:20220227T160000\n"
"DESCRIPTION:\\n--------\\n同日入替 : true\\n前回ゲスト数 : 2\\n次回\n"
"SUMMARY:★ xxx (xxx / xxx xxx)\n"
"END:VEVENT")
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