# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = (r"(?s)(?:.*(?:datetime:)(?<datetime>.*?)(?:$|\s*\|))?(?:.*(?:hostname:)(?<hostname>.*?)(?:$|\s*\|))?(?:.*(?:threadId:)(?<threadId>.*?)(?:$|\s*\|))?(?:.*(?:userId:)(?<userId>.*?)(?:$|\s*\|))?(?:.*(?:correlationId:)(?<correlationId>.*?)(?:$|\s*\|))?(?:.*(?:applicationName:)(?<applicationName>.*?)(?:$|\s*\|))?(?:.*(?:direction:)(?<direction>.*?)(?:$|\s*\|))?(?:.*(?:operationName:)(?<operationName>.*?)(?:$|\s*\|))?(?:.*(?:className:)(?<className>.*?)(?:$|\s*\|))?(?:.*(?:methodName:)(?<methodName>.*?)(?:$|\s*\|))?(?:.*(?:latency:)(?<latency>.*?)(?:$|\s*\|))?(?:.*(?:clusterName:)(?<clusterName>.*?)(?:$|\s*\|))?(?:.*(?:webServiceType:)(?<webServiceType>.*?)(?:$|\s*\|))?(?:.*(?:strCode:)(?<strCode>.*?)(?:$|\s*\|))?(?:.*(?:strDescription:)(?<strDescription>.*?)(?:$|\s*\|))?(?:.*(?:payload:)(?<payload>.*?)(?:$|\s*\|))?(?:.*(?:requestVerb:)(?<requestVerb>.*?)(?:$|\s*\|))?(?:.*(?:httpStatusCode:)(?<httpStatusCode>.*?)(?:$|\s*\|))?(?:.*(?:httpHeaders:)(?<httpHeaders>.*?)(?:$|\s*\|))?(?:.*(?:requestUrl:)(?<requestUrl>.*?)(?:$|\s*\|))?(?:.*(?:code:)(?<code>.*?)(?:$|\s*\|))?(?:.*(?:strSystemName:)(?<strSystemName>.*?)(?:$|\s*\|))?(?:.*(?:description:)(?<description>.*?)(?:$|\s*\|))?(?:.*(?:content\-length:)(?<content_length>.*?)(?:\s*\|))?(?:.*(?:logMessage:)(?<logMessage>.*?)(?:$|\s*\|))?\n")
test_str = ("[INFO] 28 Jun 2018 14:02:29,480 SYSLOG->|datetime:20180628140229479+0000|hostname:marketingprofile-deployment-877c7f857-cv9d6/10.44.0.15(10.44.0.15)|threadId:47-http-nio-11551-exec-1(main)|userId:null|correlationId:c7943b58-a584-4cba-ad44-45cf1af3a400|applicationName:RETRIEVEMARKETINGPROFILE-V1|direction:ENTERING|operationName:RetrievalService|className:LogServletFilter|methodName:logRequest|clusterName:TXH|webServiceType:REST|payload:<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><!--<INPUTINFO> <BBCAN>8881008923</BBCAN> </INPUTINFO>--><INPUTINFO> <APPLICATIONID>NCOG</APPLICATIONID> <CLINETREQUESTID>test</CLINETREQUESTID> <VISION> <CUSTOMERID>151862438</CUSTOMERID> <ACCOUNTID>0001</ACCOUNTID> </VISION> <!--<VOICECAN>0178430862672</VOICECAN>--> <!-- <BBCAN>060002792607</BBCAN> --> <!--<BTN>2016221232</BTN> --> <!-- <ADDRESS> <ADDRESSID>030862772</ADDRESSID> <STATE>MD</STATE> </ADDRESS> --> <!--<SSPBAN>0178430862772</SSPBAN>--> <!--<PCAN>E100007652</PCAN> --> </INPUTINFO>|requestVerb:POST|httpHeaders:content-length={534};ssp-correlationid={c7943b58-a584-4cba-ad44-45cf1af3a400};host={10.44.0.15:11551};content-type={text/xml};connection={Keep-Alive};accept-encoding={gzip};user-agent={Apache-HttpClient/4.1.1 (java 1.5)};|requestUrl:http://10.44.0.15:11551/retrieveMarketingProfile/RetrievalService?null\n"
"Security framework of XStream not initialized, XStream is probably vulnerable.\n"
"[INFO] 28 Jun 2018 14:02:29,592 SYSLOG->|datetime:20180628140229591+0000|hostname:marketingprofile-deployment-877c7f857-cv9d6/10.44.0.15(10.44.0.15)|threadId:47-http-nio-11551-exec-1(main)|userId:null|correlationId:c7943b58-a584-4cba-ad44-45cf1af3a400|applicationName:RETRIEVEMARKETINGPROFILE-V1|direction:ENTERING|className:com.verizon.ssp.gateway.adapter.WebServiceAdaptor|clusterName:TXH|webServiceType:REST|payload:<!--<INPUTINFO>\n"
"<BBCAN>8881008923</BBCAN>\n"
"</INPUTINFO>-->\n"
"<INPUTINFO>\n"
" <APPLICATIONID>NCOG</APPLICATIONID>\n"
" <CLINETREQUESTID>test</CLINETREQUESTID>\n"
"<VISION>\n"
" <CUSTOMERID>151862438</CUSTOMERID>\n"
" <ACCOUNTID>0001</ACCOUNTID>\n"
"</VISION>\n"
"<!--<VOICECAN>0178430862672</VOICECAN>-->\n"
"<!-- <BBCAN>060002792607</BBCAN> -->\n"
"<!--<BTN>2016221232</BTN> -->\n"
"<!-- <ADDRESS> \n"
" <ADDRESSID>030862772</ADDRESSID>\n"
" <STATE>MD</STATE>\n"
"</ADDRESS> -->\n"
"<!--<SSPBAN>0178430862772</SSPBAN>-->\n"
"<!--<PCAN>E100007652</PCAN> -->\n"
"</INPUTINFO>|content-length:534|logMessage:<!--<INPUTINFO>\n"
"<BBCAN>8881008923</BBCAN>\n"
"</INPUTINFO>-->\n"
"<INPUTINFO>\n"
" <APPLICATIONID>NCOG</APPLICATIONID>\n"
" <CLINETREQUESTID>test</CLINETREQUESTID>\n"
"<VISION>\n"
" <CUSTOMERID>151862438</CUSTOMERID>\n"
" <ACCOUNTID>0001</ACCOUNTID>\n"
"</VISION>\n"
"<!--<VOICECAN>0178430862672</VOICECAN>-->\n"
"<!-- <BBCAN>060002792607</BBCAN> -->\n"
"<!--<BTN>2016221232</BTN> -->\n"
"<!-- <ADDRESS> \n"
" <ADDRESSID>030862772</ADDRESSID>\n"
" <STATE>MD</STATE>\n"
"</ADDRESS> -->\n"
"<!--<SSPBAN>0178430862772</SSPBAN>-->\n"
"<!--<PCAN>E100007652</PCAN> -->\n"
"</INPUTINFO>\n"
"[ERROR] 28 Jun 2018 14:02:29,687 BaseDao : Consistency Level : ONE for Key Space: grid_mktprofile\n"
"[INFO]threadId:47-http-nio-11551-exec-1(main)|userId:null|correlationId:c7943b58-a584-4cba-ad44-45cf1af3a400|\n"
"[INFO]threadId:47-http-nio-11551-exec-1(main)|userId:null|correlationId:c7943b58-a584-4cba-ad44-45cf1af3a400|\n")
matches = re.finditer(regex, test_str, re.MULTILINE)
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