# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(\s|\S){0,40}\"([0-9]{1,3})\"\;\}"
test_str = ("a:1:{s:2:\"gr\";s:3:\"214\";}\n"
"a:1:{s:2:\"gr\";s:3:\"188\";}\n"
"a:1:{s:2:\"gr\";s:3:\"213\";}\n"
"a:1:{s:2:\"gr\";s:3:\"169\";}\n"
"a:1:{s:2:\"gr\";s:3:\"219\";}\n"
"a:1:{s:2:\"gr\";s:3:\"221\";}\n"
"a:1:{s:2:\"gr\";s:3:\"211\";}\n"
"a:1:{s:2:\"gr\";s:3:\"184\";}\n"
"a:1:{s:2:\"gr\";s:3:\"191\";}\n"
"a:1:{s:2:\"gr\";s:2:\"16\";}\n"
"a:1:{s:2:\"gr\";s:3:\"127\";}\n"
"a:1:{s:2:\"gr\";s:3:\"217\";}\n"
"a:1:{s:2:\"gr\";s:3:\"200\";}\n"
"a:1:{s:2:\"gr\";s:3:\"182\";}\n"
"a:1:{s:2:\"gr\";s:3:\"128\";}\n"
"a:1:{s:2:\"gr\";s:2:\"17\";}\n"
"a:1:{s:2:\"gr\";s:3:\"163\";}\n"
"a:1:{s:2:\"gr\";s:3:\"212\";}\n"
"a:1:{s:2:\"gr\";s:3:\"166\";}\n"
"a:1:{s:2:\"gr\";s:2:\"94\";}\n"
"a:1:{s:2:\"gr\";s:2:\"83\";}\n"
"a:1:{s:2:\"gr\";s:2:\"27\";}\n"
"a:1:{s:2:\"gr\";s:2:\"28\";}\n"
"a:1:{s:2:\"gr\";s:3:\"167\";}\n"
"a:1:{s:2:\"gr\";s:3:\"168\";}\n"
"a:1:{s:2:\"gr\";s:3:\"202\";}\n"
"a:1:{s:2:\"gr\";s:1:\"7\";}\n"
"a:1:{s:2:\"gr\";s:3:\"129\";}\n"
"a:1:{s:2:\"gr\";s:3:\"183\";}\n"
"a:1:{s:2:\"gr\";s:2:\"26\";}\n"
"a:1:{s:2:\"gr\";s:3:\"185\";}\n"
"a:1:{s:2:\"gr\";s:3:\"175\";}\n"
"a:1:{s:2:\"gr\";s:2:\"29\";}\n"
"a:1:{s:2:\"gr\";s:3:\"209\";}\n"
"a:1:{s:2:\"gr\";s:3:\"177\";}\n"
"a:1:{s:2:\"gr\";s:3:\"178\";}\n"
"a:1:{s:2:\"gr\";s:2:\"24\";}\n"
"a:1:{s:2:\"gr\";s:3:\"225\";}\n"
"a:1:{s:2:\"gr\";s:3:\"224\";}\n"
"a:1:{s:2:\"gr\";s:2:\"57\";}\n"
"a:1:{s:2:\"gr\";s:2:\"18\";}\n"
"a:1:{s:2:\"gr\";s:3:\"208\";}\n"
"a:1:{s:2:\"gr\";s:3:\"193\";}\n"
"a:1:{s:2:\"gr\";s:2:\"33\";}\n"
"a:1:{s:2:\"gr\";s:2:\"10\";}\n"
"a:1:{s:2:\"gr\";s:2:\"11\";}\n"
"a:1:{s:2:\"gr\";s:2:\"12\";}\n"
"a:1:{s:2:\"gr\";s:3:\"173\";}\n"
"a:1:{s:2:\"gr\";s:2:\"13\";}\n"
"a:1:{s:2:\"gr\";s:2:\"14\";}\n"
"a:1:{s:2:\"gr\";s:1:\"9\";}\n"
"a:1:{s:2:\"gr\";s:2:\"15\";}\n"
"a:1:{s:2:\"gr\";s:3:\"195\";}\n"
"a:1:{s:2:\"gr\";s:3:\"130\";}\n"
"a:1:{s:2:\"gr\";s:2:\"25\";}\n"
"a:1:{s:2:\"gr\";s:2:\"50\";}\n"
"a:1:{s:2:\"gr\";s:3:\"131\";}\n"
"a:1:{s:2:\"gr\";s:2:\"96\";}\n"
"a:1:{s:2:\"gr\";s:2:\"19\";}\n"
"a:1:{s:2:\"gr\";s:3:\"107\";}\n"
"a:1:{s:2:\"gr\";s:3:\"116\";}\n"
"a:1:{s:2:\"gr\";s:3:\"364\";}\n"
"a:1:{s:2:\"gr\";s:3:\"194\";}\n"
"a:1:{s:2:\"gr\";s:2:\"44\";}\n"
"a:1:{s:2:\"gr\";s:3:\"171\";}\n"
"a:1:{s:2:\"gr\";s:3:\"172\";}\n"
"a:1:{s:2:\"gr\";s:3:\"170\";}\n"
"a:1:{s:2:\"gr\";s:2:\"20\";}\n"
"a:1:{s:2:\"gr\";s:2:\"95\";}\n"
"a:1:{s:2:\"gr\";s:2:\"84\";}\n"
"a:1:{s:2:\"gr\";s:2:\"22\";}\n"
"a:1:{s:2:\"gr\";s:2:\"23\";}\n"
"a:1:{s:2:\"gr\";s:2:\"67\";}\n"
"a:1:{s:2:\"gr\";s:3:\"118\";}\n"
"a:1:{s:2:\"gr\";s:2:\"97\";}\n"
"a:1:{s:2:\"gr\";s:1:\"6\";}\n"
"a:1:{s:2:\"gr\";s:3:\"365\";}\n"
"a:1:{s:2:\"gr\";s:3:\"190\";}\n"
"a:1:{s:2:\"gr\";s:2:\"82\";}\n"
"a:1:{s:2:\"gr\";s:2:\"42\";}\n"
"a:1:{s:2:\"gr\";s:2:\"74\";}\n"
"a:1:{s:2:\"gr\";s:2:\"76\";}\n"
"a:1:{s:2:\"gr\";s:2:\"73\";}\n"
"a:1:{s:2:\"gr\";s:2:\"78\";}\n"
"a:1:{s:2:\"gr\";s:2:\"68\";}\n"
"a:1:{s:2:\"gr\";s:3:\"207\";}\n"
"a:1:{s:2:\"gr\";s:3:\"197\";}\n"
"a:1:{s:2:\"gr\";s:2:\"77\";}\n"
"a:1:{s:2:\"gr\";s:2:\"46\";}\n"
"a:1:{s:2:\"gr\";s:2:\"51\";}\n"
"a:1:{s:2:\"gr\";s:3:\"206\";}\n"
"a:1:{s:2:\"gr\";s:3:\"165\";}\n"
"a:1:{s:2:\"gr\";s:2:\"60\";}\n"
"a:1:{s:2:\"gr\";s:2:\"61\";}\n"
"a:1:{s:2:\"gr\";s:2:\"62\";}\n"
"a:1:{s:2:\"gr\";s:3:\"187\";}\n"
"a:1:{s:2:\"gr\";s:3:\"176\";}\n"
"a:1:{s:2:\"gr\";s:3:\"196\";}\n"
"a:1:{s:2:\"gr\";s:3:\"223\";}\n"
"a:1:{s:2:\"gr\";s:3:\"117\";}\n"
"a:1:{s:2:\"gr\";s:2:\"98\";}\n"
"a:1:{s:2:\"gr\";s:2:\"47\";}\n"
"a:1:{s:2:\"gr\";s:3:\"198\";}\n"
"a:1:{s:2:\"gr\";s:2:\"45\";}\n"
"a:1:{s:2:\"gr\";s:3:\"203\";}\n"
"a:1:{s:2:\"gr\";s:3:\"205\";}\n"
"a:1:{s:2:\"gr\";s:3:\"201\";}\n"
"a:1:{s:2:\"gr\";s:3:\"115\";}\n"
"a:1:{s:2:\"gr\";s:2:\"58\";}\n"
"a:1:{s:2:\"gr\";s:3:\"204\";}\n"
"a:1:{s:2:\"gr\";s:3:\"132\";}\n"
"a:1:{s:2:\"gr\";s:2:\"48\";}\n"
"a:1:{s:2:\"gr\";s:2:\"49\";}\n"
"a:1:{s:2:\"gr\";s:2:\"99\";}\n"
"a:1:{s:2:\"gr\";s:3:\"594\";}\n"
"a:1:{s:2:\"gr\";s:3:\"585\";}\n"
"a:1:{s:2:\"gr\";s:3:\"368\";}\n"
"a:1:{s:2:\"gr\";s:2:\"81\";}\n"
"a:1:{s:2:\"gr\";s:2:\"53\";}\n"
"a:1:{s:2:\"gr\";s:2:\"52\";}\n"
"a:1:{s:2:\"gr\";s:3:\"180\";}\n"
"a:1:{s:2:\"gr\";s:3:\"181\";}\n"
"a:1:{s:2:\"gr\";s:3:\"179\";}\n"
"a:1:{s:2:\"gr\";s:3:\"164\";}\n"
"a:1:{s:2:\"gr\";s:3:\"186\";}\n"
"a:1:{s:2:\"gr\";s:3:\"174\";}\n"
"a:1:{s:2:\"gr\";s:3:\"199\";}\n"
"a:1:{s:2:\"gr\";s:3:\"210\";}\n"
"a:1:{s:2:\"gr\";s:3:\"369\";}\n"
"a:1:{s:2:\"gr\";s:3:\"370\";}\n"
"a:1:{s:2:\"gr\";s:3:\"371\";}\n"
"a:1:{s:2:\"gr\";s:3:\"372\";}\n"
"a:1:{s:2:\"gr\";s:3:\"373\";}\n"
"a:1:{s:2:\"gr\";s:3:\"374\";}\n"
"a:1:{s:2:\"gr\";s:3:\"375\";}")
matches = re.finditer(regex, test_str)
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