# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"^(?P<timestamp>[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}-[0-9]{2}:[0-9]{2})\s+(?P<domain>[a-zA-Z0-9]+)\s+\[(?P<msgid>0[xX][0-9a-fA-F]+)\]\[(?P<msgtype>[a-zA-Z]+)\]\[(?P<msgcat>[a-zA-Z]+)\]\s+(?P<objtype>\w+)\((?P<objname>[a-zA-Z_-]+)\):\s+trans\((?P<txnum>[0-9]+)\)(.*?):\s(?P<msgtxt>.*)"
test_str = ("2016-03-16T10:30:18-05:00 DEVESB2 [0x80e0018d][ldap][error] xmlmgr(map-manager): trans(1750947) gtid(1750947): Error querying server 10.158.131.139: Error while searching; see log for details\n"
"2016-03-16T10:30:17-05:00 DEVESB2 [0x804000a1][slm][info] throttle(Throttler): trans(1279): Memory(10529899/13448300kB 78.299108 free) Pool(7052687) Ports(127732/127850) Temporary-FS(116/128MB 90.625000 free) File(OK)\n"
"2016-03-16T10:30:01-05:00 DEVESB2 [DEVESB][0x80e00176][ws-proxy][error] source-http(DEFAULT_DATA1_HTTP): trans(1750611)[172.27.137.222]: No WS-Proxy service endpoints matched request.\n")
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