I have a very long string which has nested loops. I want to extract a pattern in that.
String_Text:
some random texts......
........................
........................
{{info .................
.....texts..............
...{{ some text }}...... // nested parenthesis 1
........................
...{{ some text }}...... // nested parenthesis 2
........................
}} // End of topmost parenthesis
........................
..again some random text
........................
........................ // can also contain {{ }}
......End of string.
I want to extract all the text between the topmost parenthesis i.e.
Extracted_string:
info .................
.....texts..............
...{{ some text }}...... // nested parenthesis 1
........................
...{{ some text }}...... // nested parenthesis 2
........................
Pattern:
1.) starts with { and can be followed by any number of {.
2.) After that there can be any number of white space.
3.) The first word after that is surely info.
4.) Extract till this bracket is not closed.
What is have tried so far:
re.findall(r'\{+[^\S\r\n]*info\s*(.*(?:\r?\n.*)*)\}+')
I know this is wrong as what this does is find the last instance of } in the string. Can someone help me out in extracting text between those bracket? TIA