# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"^\s*(?<time>[^ ]* {1,2}[^ ]* [^ ]*) \[(?<pid>\d+)\] (?<macid>[\-\w]*)\s*(?<component>\w*):\s+(?<severity>\w+):\s+(?<action>\w+):\s+(?<action_status>\w+) (?<mesage>[^\(]*) (\((?<meta>.*)\))$"
test_str = ("Sep 19 09:23:01 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_request: Completed cib_modify operation for section nodes: OK (rc=0, origin=d2c-76-8a-ac-64-6e/crm_attribute/4, version=0.1352.0)\n"
"Sep 19 09:23:06 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_ping: Reporting our current digest to d2c-76-8a-ac-64-50: bc17de2aedf4d53c3f4fa8021fffd2b1 for 0.1352.0 (0xe2bf50 0)\n"
"Sep 19 09:30:53 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_request: Completed cib_modify operation for section nodes: OK (rc=0, origin=d2c-76-8a-ac-64-50/crm_attribute/4, version=0.1352.0)\n"
"Sep 19 09:30:58 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_ping: Reporting our current digest to d2c-76-8a-ac-64-50: bc17de2aedf4d53c3f4fa8021fffd2b1 for 0.1352.0 (0xe2e450 0)\n"
"Sep 19 09:37:59 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_request: Completed cib_modify operation for section nodes: OK (rc=0, origin=d2c-76-8a-ac-65-68/crm_attribute/4, version=0.1352.0)\n"
"Sep 19 09:38:04 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_ping: Reporting our current digest to d2c-76-8a-ac-64-50: bc17de2aedf4d53c3f4fa8021fffd2b1 for 0.1352.0 (0xe372d0 0)\n"
"Sep 19 09:43:25 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_request: Forwarding cib_modify operation for section nodes to master (origin=local/crm_attribute/4)\n"
"Sep 19 09:43:25 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_request: Completed cib_modify operation for section nodes: OK (rc=0, origin=d2c-76-8a-ac-64-6e/crm_attribute/4, version=0.1352.0)\n"
"Sep 19 09:43:30 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_ping: Reporting our current digest to d2c-76-8a-ac-64-50: bc17de2aedf4d53c3f4fa8021fffd2b1 for 0.1352.0 (0xe2be50 0)\n"
"Sep 19 09:46:55 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_request: Completed cib_modify operation for section nodes: OK (rc=0, origin=d2c-76-8a-ac-64-50/crm_attribute/4, version=0.1352.0)\n"
"Sep 19 09:47:00 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_ping: Reporting our current digest to d2c-76-8a-ac-64-50: bc17de2aedf4d53c3f4fa8021fffd2b1 for 0.1352.0 (0xeead20 0)\n"
"Sep 19 09:54:03 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_request: Completed cib_modify operation for section nodes: OK (rc=0, origin=d2c-76-8a-ac-65-68/crm_attribute/4, version=0.1352.0)\n"
"Sep 19 09:54:08 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_ping: Reporting our current digest to d2c-76-8a-ac-64-50: bc17de2aedf4d53c3f4fa8021fffd2b1 for 0.1352.0 (0x129d470 0)\n"
"Sep 19 10:02:51 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_request: Completed cib_modify operation for section nodes: OK (rc=0, origin=d2c-76-8a-ac-64-50/crm_attribute/4, version=0.1352.0)\n"
"Sep 19 10:02:56 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_ping: Reporting our current digest to d2c-76-8a-ac-64-50: bc17de2aedf4d53c3f4fa8021fffd2b1 for 0.1352.0 (0xe2e450 0)\n"
"Sep 19 10:03:38 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_request: Forwarding cib_modify operation for section nodes to master (origin=local/crm_attribute/4)\n"
"Sep 19 10:03:38 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_request: Completed cib_modify operation for section nodes: OK (rc=0, origin=d2c-76-8a-ac-64-6e/crm_attribute/4, version=0.1352.0)\n"
"Sep 19 10:03:43 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_ping: Reporting our current digest to d2c-76-8a-ac-64-50: bc17de2aedf4d53c3f4fa8021fffd2b1 for 0.1352.0 (0xb60f30 0)\n"
"Sep 19 10:10:11 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_request: Completed cib_modify operation for section nodes: OK (rc=0, origin=d2c-76-8a-ac-65-68/crm_attribute/4, version=0.1352.0)\n"
"Sep 19 10:10:16 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_ping: Reporting our current digest to d2c-76-8a-ac-64-50: bc17de2aedf4d53c3f4fa8021fffd2b1 for 0.1352.0 (0xd963e0 0)\n"
"Sep 19 10:18:44 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_request: Completed cib_modify operation for section nodes: OK (rc=0, origin=d2c-76-8a-ac-64-50/crm_attribute/4, version=0.1352.0)\n"
"Sep 19 10:18:49 [16818] d2c-76-8a-ac-64-6e cib: info: cib_process_ping: Reporting our current digest to d2c-76-8a-ac-64-50: bc17de2aedf4d53c3f4fa8021fffd2b1 for 0.1352.0 (0x129d4f0 0)")
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