# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(?P<device>\w+-\w+)\s+(?P<ObjectDetected>\w+.\w+.\w+.\w+.)(?P<date>\w+,\s+\w+\s+\d+,\s+\d+)\s+(?P<time>\d+:\d+:\d+\s+\w{1,2})\s+(?P<Path>[A-Z]:\\.+)\s+(?P<Type>Trojan|Virus|Worm)\s+((?P<Action>).+)((?P<Account>)((DOTIN\\)).+)\s+(?P<AVApplication>(Kaspersky).+)(?P<version>\d+.\d+.\d+.\d+)\s+((?P<Visibledate>(Monday,|Saturday,|Sunday,|Tuesday,|Wednesday,|Thursday,|Friday,))\s+(January|February|March|April|May|June|July|August|September|October|November|December)\s+(\d+,\s+\d+\s+\d+:\d+:\d+\s+\w+))\s((?P<lastConnection>(Monday,|Saturday,|Sunday,|Tuesday,|Wednesday,|Thursday,|Friday,))\s+(January|February|March|April|May|June|July|August|September|October|November|December)\s+\d+,\s+\d+\s+\d+:\d+:\d+\s+(PM|pm|AM|am))\s+(?P<IP>\d+.\d+.\d+.\d+)\s+(?P<ClientName>\w+-\w+)\s+(?P<Domain>\w+)"
test_str = ("10.20.10.0 AMIRI-PC Trojan.Win32.Waldek.ajd Wednesday, January 27, 2016 8:05:18 AM E:\\ \\{0732260D-4643-427C-A22B-F0DFA8EDE30D}.{EE225B7C-E421-47D2-A65B-AE9AB046A5F2} Trojan Result: Untreated: Trojan.Win32.Waldek.ajd User: DOTIN\\t.amiri (Active user) Object: e:\\ \\{0732260d-4643-427c-a22b-f0dfa8ede30d}.{ee225b7c-e421-47d2-a65b-ae9ab046a5f2} DOTIN\\T.AMIRI Kaspersky Endpoint Security 10 Service Pack 1 for Windows 10.2.2.10535 Monday, February 15, 2016 3:11:38 PM Monday, February 15, 2016 3:11:38 PM 10.20.10.28 AMIRI-PC DOTIN \n\n"
"------------------------------------------------------------\n\n"
"(^Trojan)\n"
"((DOTIN\\\\)(w+.\\w+))\\s+(kaspersky)\n"
"(Monday,|Saturday,|Sunday,|Tuesday,|Wednesday,|Thursday,|Fridy,)\n\n"
"&&(\\s+(February)|)\\s+\\d+\\s+\\d+,\\s+\\d+\\s+(\\d+:\\d+:\\d+\\s+\\w+\\s+\\w+\n"
"(?P<Type>Trojan|Virus|Worm)\n"
"+(?P<Account>)\n"
"(?P<AVApplication>\n"
"?P<Visible>(Monday,|Saturday,|Sunday,|Tuesday,|Wednesday,|Thursday,|Friday,)\\s+(January|February|March|April|May|June|July|August|September|October|November|December)\n"
"?P<version>\n"
"?P<lastConnection>\\")
matches = re.search(regex, test_str)
if matches:
print ("Match was found at {start}-{end}: {match}".format(start = matches.start(), end = matches.end(), match = matches.group()))
for groupNum in range(0, len(matches.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = matches.start(groupNum), end = matches.end(groupNum), group = matches.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