# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"^(.*\[(error|warning|notice|info|debug)\].*)$"
test_str = ("lu2-pre-sm-swap-manager1 (192.168.236.230) 2014-07-24 14:09:27,193 [debug] PRE-BCP 213.146.188.31 [marti.us] bcp:4934846 GET 3a90f85c /members/overview session_id: 5037d3bfa31 version: 1.54.0-SNAPSHOT-11881644 ROOT.src.Company.Departments:91...ROOT.src.Core.Database:263...ROOT.src.Core.Statistics:390: Memory usage: 7.63MB (8.00MB real), max 7.83MB (8.00MB real)\n"
"lu2-pre-sm-swap-manager1 (192.168.236.230) 2014-07-24 14:09:27,193 [debug] PRE-BCP 213.146.188.31 [marti.us] bcp:4934846 GET 3a90f85c /members/overview session_id: 5037d3bfa31 version: 1.54.0-SNAPSHOT-11881644 ROOT.src.Company.Departments:91...ROOT.src.Core.Database:263...ROOT.src.Core.Database:513: DB CACHE GET OK (total: 0, cache: 0): bcp_departments-4934846.3903997f7fe55eb81eaa07fc5e598ba0\n"
"lu2-pre-sm-swap-manager1 (192.168.236.230) 2014-07-24 14:09:27,194 [debug] PRE-BCP 213.146.188.31 [marti.us] bcp:4934846 GET 3a90f85c /members/overview session_id: 5037d3bfa31 version: 1.54.0-SNAPSHOT-11881644 ROOT.src.Company.Departments:91...ROOT.src.Core.Database:263...ROOT.src.Service.Cache.Request:72: REQUEST CACHE SET \"bcp_departments-4934846.3903997f7fe55eb81eaa07fc5e598ba0\" : object\n"
"lu2-pre-sm-swap-manager1 (192.168.236.230) 2014-07-24 14:09:27,237 [debug] PRE-BCP 213.146.188.31 [marti.us] bcp:4934846 GET 3a90f85c /members/overview session_id: 5037d3bfa31 version: 1.54.0-SNAPSHOT-11881644 ROOT.src.Service.Feature:140: get_real_value (webtracking, skype, GB): 1\n"
"lu2-pre-sm-swap-manager1 (192.168.236.230) 2014-07-24 14:09:27,240 [debug] PRE-BCP 213.146.188.31 [marti.us] bcp:4934846 GET 3a90f85c /members/overview session_id: 5037d3bfa31 version: 1.54.0-SNAPSHOT-11881644 ROOT.src.Swap.Application2:553: serve_endpoint (members/overview): OK")
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