# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"<(?<key>[^>]+)>(?<value>[^<]+)<\/\1>"
test_str = "[2015-08-10T15:00:03.644+1000] | INFO | cessAuditorEvent | updateNetworkResource | 188 - ib2b-common-lib - 3.0.4074 | 1c679b99-2235-4027-93a5-9f9b91822c77 | 9e9 ib2b-bs-manage-network-resource_3.0.4074 WorkforceManagement NBNTEST01 ? HEADER [activityName=\"updateNetworkResource\", msgName=\"ManageNetworkResourceupdateNetworkResourceError\", businessServiceName=\"ManageNetworkResource\", businessServiceVersion=\"V1.0\", msgType=\"Error\", accessSeekerId=\"NBNTEST01\", replyToURI=\"SERVICE.BS.MANAGE_NETWORK_RESOURCE.V1.RESP.WWM\", activityStatus=\"Failure\", correlationId=\"1c679b99-2235-4027-93a5-9f9b91822c77\", security=\"Placeholder Security\", priority=\"4\", communicationPattern=\"RequestReply\", timestamp=\"2015-08-10T05:00:03Z\", businessChannel=\"WorkforceManagement\", headerCharacteristicValue=\"[Mocked:TRUE]\"] MESSAGE [<?xml version=\"1.0\" encoding=\"UTF-8\"?><soapenv:Fault xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:exp=\"http://www.nbnco.com.au/cim/common/exception/v5\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:nbnfn=\"http://www.nbnco.com.au/functions\"><faultcode>exp:TechnicalException</faultcode><faultstring>000000: A technical error has occurred during the processing of the request.</faultstring><detail><exp:TechnicalException><Exception><ID>000000</ID><description>A technical error has occurred during the processing of the request.</description><type>Error</type><ReferencesApplicationException><returnType>Technical</returnType><returnCode>PNI-TEC-0003</returnCode><returnDescription>A data issue has prevented the application from processing the request.</returnDescription></ReferencesApplicationException></Exception></exp:TechnicalException></detail></soapenv:Fault>] [jms://queue:SERVICE.BS.MANAGE_NETWORK_RESOURCE.V1.RESP.WWM (12ms taken)] [ExchangeSentEvent]"
matches = re.finditer(regex, test_str, re.DOTALL)
for matchNum, match in enumerate(matches, start=1):
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
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