# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(\w*)=(\".*?\"|\S*)"
test_str = ("Message meets Alert condition\n\n"
"date=2020-08-20 time=00:33:57 devname=FGT3HD3999906624 devid=FGT3HD3999906624 logid=\"0100032003\" type=\"event\" subtype=\"system\" level=\"information\" vd=\"root\" eventtime=1597847637407862934 tz=\"+1000\" logdesc=\"Admin logout successful\" sn=\"159999794\" user=\"admin\" ui=\"https(10.198.199.105)\" method=\"https\" srcip=10.198.199.105 dstip=192.168.23.254 action=\"logout\" status=\"success\" duration=4843 reason=\"timeout\" msg=\"Administrator admin timed out on https(10.198.199.105)\"\n\n"
"Administrator IT Administrator Ph:")
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