import re
regex = re.compile((r"^.*\bgetHouseName:\h+(.+)(?:\R(?!.*price).*)*\R.*price\h+\(in doll\)\h+\[min:\h+(\d+),\h+max:\h+(\d+)\](?:\R(?!.*squaremtr).*)*\R.*squaremtr\h+\(in doll\)\h+\[min: (\d+),\h+max:(\d+)\](?:\R(?!.*sellVal).*)*\R.*sellVal\h+\(in doll\)\h+\[min:\h+(\d+),\h+max:\h+(\d+)\](?:\R(?!.*rentPrice).*)*\R.*rentPrice\(in doll\)\h+\[min: (\d+),\h+max:\h+(\d+)\]\n"), flags=re.MULTILINE)
test_str = ("[04:04:04s] [startedRetrieving]getHouseName: house1\n"
"[04:04:04s] [startedRetrieving]random useless text\n"
"[04:04:04s] [startedRetrieving]price (in doll) [min: 1000, max: 1200]\n"
"[04:04:05s] [startedRetrieving]squaremtr (in doll) [min: 75, max:85]\n"
"[04:04:04s] [startedRetrieving]sellVal (in doll) [min: 1000, max: 1200]\n"
"[04:04:05s] [startedRetrieving]random useless text\n"
"[04:04:05s] [startedRetrieving]random useless text\n"
"[04:04:05s] [startedRetrieving]random useless text\n"
"[04:04:05s] [startedRetrieving]rentPrice(in doll) [min: 150, max: 200]\n"
"[04:06:04s] [startedRetrieving]getHouseName: house2\n"
"[04:06:04s] [startedRetrieving]price(in doll) [min: 1004, max 1100]\n"
"[04:06:04s] [startedRetrieving]squaremtr(in doll) [min: 85, max 99]\n"
"[04:06:04s] [startedRetrieving]sellVal(in doll) [min: 950, max: 1050]\n"
"[04:06:04s] [startedRetrieving]random useless text\n"
"[04:06:04s] [startedRetrieving]rentPrice(in doll) [min: 150, max: 290]\n"
"[04:09:04s] [startedRetrieving]getHouseName: house3\n"
"[04:09:04s] [startedRetrieving]price(in doll) [min: 1099, max: 1200]\n"
"[04:09:04s] [startedRetrieving]squaremtr(in doll) [min: 90, max: 110]\n"
"[04:09:04s] [startedRetrieving]random useless text\n"
"[04:09:04s] [startedRetrieving]random useless text\n"
"[04:09:04s] [startedRetrieving]sellVal(in doll) [min: 1100, max: 1300]\n"
"[04:09:04s] [startedRetrieving]random useless text\n"
"[04:09:04s] [startedRetrieving]rentPrice(in doll) [min: 199, max: 300]")
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