I'm trying to find a way to parse the following string, into a list of strings using regex.
{"first_statement" : 1, "bleh" : { "some_data" : True } }, {"second_statement" : 2}
# Group 1:
{"first_statement" : 1, "bleh" : { "some_data" : True } }
# Group 2:
{"second_statement" : 2}
I want my regex to match the most outer braces pattern, no matter how many internal braces there are. For instance...
{"first_statement" : 1, "bleh" : { "some_data" : True, "foo" : { "bar" : { "zing" : False } } } }
# Group 1:
{"first_statement" : 1, "bleh" : { "some_data" : True, "foo" : { "bar" : { "zing" : False } } } }
I haven't got much experience with regex, but I tried some things, and the closer I got is a simple pattern... {.*?}
, but it obviously closed my match when it first encountered a closing braces. Until then, all my other attempts failed, the closer I got was a .NET regex solution but I couldn't get it to work on python.
Is there even a way to do it using python regex, or do I have to parse my string character by character using a simple loop ? As far as I have researched exploring the All tokens of regex101, there is no simple way to achieving this.
Note : I don't care about the characters in between the first layer of braces. I want to ignore them.