# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"^([\d-\.\s\:]+)\s.*?-\s([\w\s:\.]+)(<\w+.*?)\n\d{4}"
test_str = ("2018-11-25 14:10:29.184 [ajp-bio-172.27.9.196-8009-exec-1] ERROR c.q.j.c.a.event.AuditEventHandler U:UNKNOWN SC:17618 TX:0 - SesIdCode is null. So no audit log transaction for this transaction\n"
"2018-11-25 14:10:29.184 [ajp-bio-172.27.9.196-8009-exec-1] INFO c.e.p.component.SenderComponent U:UNKNOWN SC:17618 TX:0 - SendMessage, Invockation End..\n"
"2018-11-25 14:10:38.666 [ajp-bio-172.27.9.196-8009-exec-1] DEBUG c.e.r.p.endpoint.PickerProcessor U:UNKNOWN SC:17618 TX:0 - Message Picked from the queue....<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
" <soapenv:Header />\n"
" <soapenv:Body>\n"
" <EAI_MESSAGE>\n"
" <EAI_HEADER>\n"
" <ServiceName>SMS</ServiceName>\n"
" <ServiceType>SendSms</ServiceType>\n"
" <ServiceVersion>1.0</ServiceVersion>\n"
" <Client>xx</Client>\n"
" <ClientChannel>SBA</ClientChannel>\n"
" <MsgChannel>WebServices</MsgChannel>\n"
" <SecurityInfo>\n"
" <Authentication>\n"
" <UserId>xxx</UserId>\n"
" <Password>xxx</Password>\n"
" </Authentication>\n"
" <Authorization>\n"
" <UserId>xxx</UserId>\n"
" </Authorization>\n"
" </SecurityInfo>\n"
" <SnapIns>\n"
" <NameValue Name=\"\" Value=\"\" />\n"
" </SnapIns>\n"
" <RequestorLanguage>E</RequestorLanguage>\n"
" <EaiReference>0</EaiReference>\n"
" <ReturnCode>0000</ReturnCode>\n"
" </EAI_HEADER>\n"
" <EAI_BODY>\n"
" <EAI_REQUEST>\n"
" <SendSmsRequest>\n"
" <RefID>502521</RefID>\n"
" <ISD>974</ISD>\n"
" <PhoneNO>xxx</PhoneNO>\n"
" <Message>Dear User, Your unique OTP pin for xxx is xxxx</Message>\n"
" <Language>E</Language>\n"
" <Priority>2</Priority>\n"
" <SchDate />\n"
" <SrcKey>xx</SrcKey>\n"
" <Department>xx xx</Department>\n"
" <SMSUser>SMS Alerter</SMSUser>\n"
" </SendSmsRequest>\n"
" </EAI_REQUEST>\n"
" </EAI_BODY>\n"
" </EAI_MESSAGE>\n"
" </soapenv:Body>\n"
"</soapenv:Envelope>\n"
"2018-11-25 14:10:38.666 [ajp-bio-172.27.9.196-8009-exec-1] INFO c.e.r.process.GenericProcessor U:UNKNOWN SC:17618 TX:0 - Starting the processor -com.eix.processor.persistence.InPersisterProcessor\n"
"2018-11-25 14:27:58.099 [ajp-bio-172.27.9.196-8009-exec-1] INFO c.e.w.c.i.impl.CheckInServiceImpl U:UNKNOWN SC:17740 TX:0 - Invoking webservice http://alteainterface.qatarairways.com.qa/AlteaODS/AlteaODS.svc\n"
"2018-11-25 14:27:58.178 [ajp-bio-172.27.9.196-8009-exec-1] INFO c.e.w.c.i.impl.CheckInServiceImpl U:UNKNOWN SC:17740 TX:0 - Response Message : <MESSAGE><HEADER><ServiceName>xxxx xxxx</ServiceName><ServiceType>PassengerInfo</ServiceType><ServiceVersion>1.0</ServiceVersion><Client>xxx</Client><ClientChannel>xx</ClientChannel><MsgChannel>WebServices</MsgChannel><SecurityInfo><Authentication><UserId>xx</UserId><Password>xxx</Password></Authentication></SecurityInfo></HEADER><BODY><RESPONSE><passengerStatus>Invalid</passengerStatus><RegisteredFlight></RegisteredFlight><passengerPhone></passengerPhone><passengerEmail></passengerEmail><FFPNumber></FFPNumber></RESPONSE></BODY></MESSAGE>\n"
"2018-11-25 14:27:58.178 [ajp-bio-172.27.9.196-8009-exec-1] INFO c.e.r.process.GenericProcessor U:UNKNOWN SC:17740 TX:0 - Starting the processor -com.eix.processor.persistence.OutPersisterProcessor\n"
"2018-11-25 14:27:58.178 [ajp-bio-172.27.9.196-8009-exec-1] INFO \n")
matches = re.finditer(regex, test_str, re.MULTILINE | 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