# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"\{.*\[type=(.*),\s*reason=(.*)],\s*data=.*\}"
test_str = "[10:58:56] [INFO] [cn.qstec.gateway.filter.es.DaptSaveOrUpdateResponseGatewayFilterFactory] [] [-] [-] [返回体===>{code=1, state=false, message=upsert failed index [cards_house_translation] type _doc id hr1811-116-IH Exception Elasticsearch exception [type=illegal_argument_exception, reason=Document contains at least one immense term in field=\"article_translation\" (whose UTF8 encoding is longer than the max length 32766), all of which were skipped. Please correct the analyzer to not produce such terms. The prefix of the first immense term is: '[60, 104, 116, 109, 108, 32, 120, 109, 108, 110, 115, 58, 109, 115, 61, 34, 117, 114, 110, 58, 115, 99, 104, 101, 109, 97, 115, 45, 109, 105]...', original message: bytes can be at most 32766 in length; got 44979], data=}]"
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