# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"^.*?CEF:\d+\|(?<severity>.*?)\|(?<group>.*?)\|(?<process>\d+)\|-SiteId\s\((?<processid>\d+)\)\s(?<url>.*?)\s.[^\s]+\s(?<recipient>.*?)\|-RuleName\s(?<threatname>[^\|]+)\|-ActionTakenRequest(?<action>[^\|]+)\|EntryPage\s(?<subject>.*?)\s"
test_str = ("may. 30 07:04:32 host CEF:0|Security Events|ThreatAlert|869000350019695021|-SiteId (227349) bancaenlinea.bicsa.com -VisitCountry Germany|-RuleName Bad Bots|-ActionTakenRequest blocked |EntryPage bancaenlinea.bicsa.com/user/register//user/register/ -ClienteApp Chinese Vulnerability Scanner:1 -Ip 212.124.114.242-NumRequests 1 -AttemptedOn URL -AttackVectorInternalCode 200.0\n"
"may. 26 21:41:22 host CEF:0|Security Events|ThreatAlert|1000000270132476675|-SiteId (226911) www.bicsa.com -VisitCountry United States|-RuleName Bad Bots|-ActionTakenRequest blocked |EntryPage www.bicsa.com/robots.txt/robots.txt -ClienteApp LTX71:1 -Ip 35.226.23.240-NumRequests 1 -AttemptedOn URL -AttackVectorInternalCode 200.0\n"
"may. 27 17:13:21 host CEF:0|Security Events|ThreatAlert|432001330089612747|-SiteId (226911) www.bicsa.com -VisitCountry China|-RuleName Bad Bots|-ActionTakenRequest blocked |EntryPage www.bicsa.com/es/es -ClienteApp YisouSpider:1 -Ip 106.11.153.199-NumRequests 1 -AttemptedOn URL -AttackVectorInternalCode 200.0\n"
"may. 27 17:13:22 host CEF:0|Security Events|ThreatAlert|432001330089614196|-SiteId (226911) www.bicsa.com -VisitCountry China|-RuleName Bad Bots|-ActionTakenRequest blocked |EntryPage www.bicsa.com/robots.txt/robots.txt -ClienteApp YisouSpider:1 -Ip 106.11.155.219-NumRequests 2 -AttemptedOn URL -AttackVectorInternalCode 200.0\n"
"may. 27 17:13:22 host CEF:0|Security Events|ThreatAlert|432001330089614196|-SiteId (226911) www.bicsa.com -VisitCountry China -VisitCountry China|-RuleName Bad Bots|-ActionTakenRequest blocked |EntryPage www.bicsa.com/robots.txt/robots.txt -ClienteApp YisouSpider:1 -Ip 106.11.155.219-NumRequests 2/robots.txt -ClienteApp YisouSpider:1 -Ip 106.11.155.219-NumRequests 2 -AttemptedOn URL -AttackVectorInternalCode 200.0\n"
"may. 31 06:29:22 host CEF:0|Security Events|ThreatAlert|156000740014728873|-SiteId (226911) www.bicsa.com -VisitCountry United States -VisitCountry United States -VisitCountry United States -VisitCountry United States -VisitCountry United States -VisitCountry United States -VisitCountry United States -VisitCountry United States -VisitCountry United States -VisitCountry United States -VisitCountry United States -VisitCountry United States -VisitCountry United States -VisitCountry United States -VisitCountry United States -VisitCountry United States -VisitCountry United States -VisitCountry United States -VisitCountry United States -VisitCountry United States -VisitCountry United States -VisitCountry United States -VisitCountry United States|-RuleName DDoS|-ActionTakenRequest suspended |EntryPage www.bicsa.com/www.bicsa.com/ -ClienteApp Bot:1 -Ip 138.197.77.70-NumRequests 1www.bicsa.com/ -ClienteApp Bot:1 -Ip 138.197.77.70-NumRequests 1/robots.txt -ClienteApp Bot:1 -Ip 138.197.77.70-NumRequests 1/pub/nuevo-formato-de-cheques/ -ClienteApp Bot:1 -Ip 138.197.77.70-NumRequests 1/cuentas-corrientes/ -ClienteApp Bot:1 -Ip 138.197.77.70-NumRequests 1/contacto/ -ClienteApp Bot:1 -Ip 138.197.77.70-NumRequests 1/cobranzas/ -ClienteApp Bot:1 -Ip 138.197.77.70-NumRequests 1/corporativa/ -ClienteApp Bot:1 -Ip 138.197.77.70-NumRequests 1/finanzas-estructuradas/ -ClienteApp Bot:1 -Ip 138.197.77.70-NumRequests 1/personal/ -ClienteApp Bot:1 -Ip 138.197.77.70-NumRequests 1/ordenes-de-pago/ -ClienteApp Bot:1 -Ip 138.197.77.70-NumRequests 1/ordenes-de-pago-2/ -ClienteApp Bot:1 -Ip 138.197.77.70-NumRequests 1/certificado/ -ClienteApp Bot:1 -Ip 138.197.77.70-NumRequests 1/e-banking/ -ClienteApp Bot:1 -Ip 138.197.77.70-NumRequests 1/acerca-de-bicsa/ -ClienteApp Bot:1 -Ip 138.197.77.70-NumRequests 1/infopersonal/ -ClienteApp Bot:1 -Ip 138.197.77.70-NumRequests 1/bicsacapital/ -ClienteApp Bot:1 -Ip 138.197.77.70-NumRequests 1/phishing/ -ClienteApp Bot:1 -Ip 138.197.77.70-NumRequests 1/mapa-del-sitio/ -ClienteApp Bot:1 -Ip 138.197.77.70-NumRequests 1/reportefraude/ -ClienteApp Bot:1 -Ip 138.197.77.70-NumRequests 1/en/ -ClienteApp Bot:1 -Ip 138.197.77.70-NumRequests 1/seguridad-y-privacidad/ -ClienteApp Bot:1 -Ip 138.197.77.70-NumRequests 1/servicios/ -ClienteApp Bot:1 -Ip 138.197.77.70-NumRequests 1\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