If I have a string where there is a valid JSON substring like this one:
mystr = '100{"1":2, "3":4}312'
What is the best way to do extract just the JSON string? The numbers outside can be anything (except a { or }), including newlines and things like that.
Just to be clear, this is the result I want
newStr = '{"1":2, "3":4}'
The best way I can think of do this is to use find and rfind and then take the substring. This seems too verbose to me and it isn’t python 3.0 compliant (which I would prefer but is not essential)
Any help is appreciated.
Note that the following code very much assumes that there is nothing other than non-bracket material on either side of the JSON string.
The short, non-precompiled, non-commented version:
Although for the sake of maintenance, commenting regular expressions is very much preferred.