# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(.*?<SYSD:INFO>.*?severity=\"info\".*?(sys=(\"SecureWeb\"|\"SecureNet\").*?(action=\"pass\"|fwrule=\"60001\")).*|.*?<LOC\d:NOTE>.*)"
test_str = ("09 04 2019 10:46:13 10.69.137.81 <SYSD:INFO> 2019:09:04-10:46:13 wf-tg-utm-2 httpproxy[26178]: id=\"0001\" severity=\"info\" sys=\"SecureWeb\" sub=\"http\" name=\"http access\" action=\"pass\" method=\"GET\" srcip=\"192.168.128.67\" dstip=\"104.31.8.169\" user=\"\" group=\"\" ad_domain=\"\" statuscode=\"403\" cached=\"0\" profile=\"REF_HttProContaInterNetwo10 (Wireless Hotspot)\" filteraction=\"REF_HttCffDefauAllowGuest (Default Allow (Guest))\" size=\"3057\" request=\"0xd50f0e00\" url=\"http://exmaple.com/\" referer=\"\" error=\"\" authtime=\"0\" dnstime=\"92\" aptptime=\"88\" cattime=\"92\" avscantime=\"4513\" fullreqtime=\"18114\" device=\"0\" auth=\"0\" ua=\"\" exceptions=\"ssl,certcheck,certdate,application,patience\" category=\"177\" reputation=\"neutral\" categoryname=\"Content Server\" sandbox=\"-\" content-type=\"text/html\"\n"
"09 04 2019 10:38:33 10.69.137.81 <LOC6:NOTE> 2019:09:04-10:38:33 wf-tg-utm-2 httpd: 192.168.129.115 - - [04/Sep/2019:10:38:33 +0100] \"GET /bag?v=1 HTTP/1.1\" 302 -\n"
"09 05 2019 13:44:24 10.69.137.81 <SYSD:INFO> 2019:09:05-13:44:24 wf-tg-utm-2 httpproxy[26178]: id=\"0001\" severity=\"info\" sys=\"SecureWeb\" sub=\"http\" name=\"http access\" action=\"pass\" method=\"GET\" srcip=\"10.69.202.41\" dstip=\"185.187.118.2\" user=\"Da088518\" group=\"AD Proxy Users (WBS)\" ad_domain=\"CYMRU\" statuscode=\"200\" cached=\"0\" profile=\"REF_HttProContaInterNetwo4 (Clients (DHCP/Static))\" filteraction=\"REF_HttCffDefauAllow (Default Allow)\" size=\"42\" request=\"0xdab72a00\" url=\"http://lgen.idgconnect.com/t/1hxnDKGABJ.png\" referer=\"\" error=\"\" authtime=\"679\" dnstime=\"3236\" aptptime=\"86\" cattime=\"20119\" avscantime=\"975\" fullreqtime=\"276035\" device=\"0\" auth=\"2\" ua=\"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; Tablet PC 2.0; wbx 1.0.0; Microsoft Outlook 16.0.4873; Microsoft Outlook 16.0.4873; ms-office; MSOffice \" exceptions=\"\" category=\"105\" reputation=\"neutral\" categoryname=\"Business\" sandbox=\"-\" content-type=\"image/gif\"\n"
"09 05 2019 13:44:24 10.69.137.81 <SYSD:INFO> 2019:09:05-13:44:24 wf-tg-utm-2 httpproxy[26178]: id=\"0001\" severity=\"info\" sys=\"SecureWeb\" sub=\"http\" name=\"http access\" action=\"pass\" method=\"CONNECT\" srcip=\"10.69.202.41\" dstip=\"104.24.31.38\" user=\"Da088518\" group=\"AD Proxy Users (WBS)\" ad_domain=\"CYMRU\" statuscode=\"200\" cached=\"0\" profile=\"REF_HttProContaInterNetwo4 (Clients (DHCP/Static))\" filteraction=\"REF_HttCffDefauAllow (Default Allow)\" size=\"134746\" request=\"0xd55f1800\" url=\"https://image.chitra.live/\" referer=\"\" error=\"\" authtime=\"404\" dnstime=\"1204\" aptptime=\"98\" cattime=\"20482\" avscantime=\"0\" fullreqtime=\"2888600\" device=\"0\" auth=\"2\" ua=\"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; Tablet PC 2.0; wbx 1.0.0; Microsoft Outlook 16.0.4873; Microsoft Outlook 16.0.4873)\" exceptions=\"\" category=\"177\" reputation=\"neutral\" categoryname=\"Content Server\"\n"
"09 05 2019 13:44:24 10.69.137.81 <SYSD:INFO> 2019:09:05-13:44:23 wf-tg-utm-2 ulogd[10129]: id=\"2001\" severity=\"info\" sys=\"SecureNet\" sub=\"packetfilter\" name=\"Packet dropped\" action=\"drop\" fwrule=\"60001\" initf=\"eth7\" srcmac=\"44:e4:d9:8f:dd:c2\" dstmac=\"00:1a:8c:f0:ca:67\" srcip=\"40.100.174.18\" dstip=\"159.86.176.10\" proto=\"6\" length=\"40\" tos=\"0x00\" prec=\"0x00\" ttl=\"240\" srcport=\"993\" dstport=\"54752\" tcpflags=\"RST\" \n\n\n\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