import re
regex = re.compile(r"^(.*\[(error|warning|notice|info|debug)\].*)$", flags=re.MULTILINE)
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 = regex.finditer(test_str)
for match_num, match in enumerate(matches, start=1):
print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}")
for group_num, group in enumerate(match.groups(), start=1):
print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")
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