import re
regex = re.compile(r"ContactMessageTransport[\w\W]*?Started<\/pogo:Status>", flags=re.MULTILINE)
test_str = (" <getAllMessageQueueInfoResponse xmlns=\"http:abcd.com/MessageQueueAnalyticsAPI\">\n"
" <return>\n"
" <Entry xmlns:pogo=\"http://example.com/com/integration/services/messagequeueanalyticsservice\">\n"
" <pogo:AckCount>0</pogo:AckCount>\n"
" <pogo:DestinationID>0</pogo:DestinationID>\n"
" <pogo:ErrorCount>25</pogo:ErrorCount>\n"
" <pogo:ID>67</pogo:ID>\n"
" <pogo:Latest>2017-11-28T00:00:00-05:00</pogo:Latest>\n"
" <pogo:Name>ContactMessageTransport</pogo:Name>\n"
" <pogo:NotAckCount>0</pogo:NotAckCount>\n"
" <pogo:Oldest>2017-11-28T00:00:00-05:00</pogo:Oldest>\n"
" <pogo:RetryableErrorCount>31</pogo:RetryableErrorCount>\n"
" <pogo:SkippedCount>0</pogo:SkippedCount>\n"
" <pogo:Status>Started</pogo:Status>\n"
" <pogo:UnsentCount>212</pogo:UnsentCount>\n"
" </Entry>\n"
" <Entry xmlns:pogo=\"http://example.com/com/integration/services/messagequeueanalyticsservice\">\n"
" <pogo:AckCount>0</pogo:AckCount>\n"
" <pogo:DestinationID>0</pogo:DestinationID>\n"
" <pogo:ErrorCount>0</pogo:ErrorCount>\n"
" <pogo:ID>65</pogo:ID>\n"
" <pogo:Latest>2018-03-17T00:00:00-04:00</pogo:Latest>\n"
" <pogo:Name>Email</pogo:Name>\n"
" <pogo:NotAckCount>0</pogo:NotAckCount>\n"
" <pogo:Oldest>2018-03-17T00:00:00-04:00</pogo:Oldest>\n"
" <pogo:RetryableErrorCount>4</pogo:RetryableErrorCount>\n"
" <pogo:SkippedCount>0</pogo:SkippedCount>\n"
" <pogo:Status>Started</pogo:Status>\n"
" <pogo:UnsentCount>0</pogo:UnsentCount>\n"
" </Entry>")
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