import re
regex = re.compile(r"^\}$", flags=re.MULTILINE)
test_str = ("{\n"
" \"_score\": 1.0,\n"
" \"_index\": \"newsvit\",\n"
" \"_source\": {\n"
" \"content\": \" \\u0641\\u0647\\u06cc\\u0645\\u0647 \\u062d\\u0633\\u0646\\u200c\\u0645\\u06cc\\u0631\\u06cc: \",\n"
" \"title\": \"\\u06a9\\u0627\\u0631\\u0647\\u0627\\u06cc \\u0642\\u0627\\u0644\\u06cc\\u0628\\u0627\\u0641 \",\n"
" \"lead\": \"\\u062c\\u0627\\u0645\\u0639\\u0647 > \\u0634\\u0647\\u0631\\u06cc - \n"
" \\u0645\\u06cc\\u0632\\u06af\\u0631\\u062f\\u06cc \\u062f\\u0631\\u0628\\u0627\\u0631\\u0647 .\",\n"
" \"agency\": \"13\",\n"
" \"date_created\": 1494518193,\n"
" \"url\": \"http://www.khabaronline.ir/(X(1)S(bud4wg3ebzbxv51mj45iwjtp))/detail/663749/society/urban\",\n"
" \"image\": \"uploads/2017/05/11/1589793661.jpg\",\n"
" \"category\": \"15\"\n"
" },\n"
" \"_type\": \"news\",\n"
" \"_id\": \"2981643\"\n"
"}\n"
"{\n"
" \"_score\": 1.0,\n"
" \"_index\": \"newsvit\",\n"
" \"_source\": {\n"
" \"content\": \"\\u0645/\\u0630\",\n"
" \"title\": \"\\u0645\\u0639\\u0646\\u0648\\u06cc\\u062a \\u062f\\u0631 \\u0639\\u0635\\u0631 \",\n"
" \"lead\": \"\\u0645\\u062f\\u06cc\\u0631 \\u0645\\u0624\\u0633\\u0633\\u0647 \\u0639\\u0644\\u0645\\u06cc \\u0648 \\u067e\\u0698\\u0648\\u0647\\u0634\\u06cc \\u0627\\u0628\\u0646\\u200c\\u0633\\u06cc\\u0646\\u0627 \\u062f\\u0631 .\",\n"
" \"agency\": \"1\",\n"
" \"date_created\": 1494521817,\n"
" \"url\": \"http://www.farsnews.com/13960221001386\",\n"
" \"image\": \"uploads/2017/05/11/1713799235.jpg\",\n"
" \"category\": \"20\"\n"
" },\n"
" \"_type\": \"news\",\n"
" \"_id\": \"2981951\"\n"
"}\n"
"....")
matches = regex.finditer(test_str)
for match_num, match in enumerate(matches, start=1):
print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}")
for group_num, group in enumerate(match.groups(), start=1):
print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")
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