import re
regex = re.compile(r"(\"filterType\":\h+\"LOT_SIZE\",(?:\R\h+\"[^\"]+\":\h+\"[^\"]+\",?){3})(?:\R\h+\"[^\"]+\":\h+\"[^\"]+\",?){3}", flags=re.MULTILINE)
test_str = ("\"symbol\": \"ETHBTC\",\n"
" \"filterType\": \"LOT_SIZE\",\n"
" \"minQty\": \"0.00100000\",\n"
" \"maxQty\": \"100000.00000000\",\n"
" \"stepSize\": \"0.00100000\"\n"
" \"minQty\": \"0.00000000\",\n"
" \"maxQty\": \"9201.00570633\",\n"
" \"stepSize\": \"0.00000000\"\n"
"\"symbol\": \"LTCBTC\",\n"
" \"filterType\": \"LOT_SIZE\",\n"
" \"minQty\": \"0.01000000\",\n"
" \"maxQty\": \"100000.00000000\",\n"
" \"stepSize\": \"0.01000000\"\n"
" \"minQty\": \"0.00000000\",\n"
" \"maxQty\": \"33144.83294363\",\n"
" \"stepSize\": \"0.00000000\"")
subst = "$1"
result = regex.sub(subst, test_str)
if result:
print(result)
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