A program outputs a file with lines of the following format
{Foo} Bar Bacon {Egg}
where Foo and Egg could, but do not have to, be made up of several words. Bar and Bacon always are a single word.
I need to get Bar in a variable for my further code. I imagine that this would work if I split the sting at a matching regular expression. This would return a list of the four elements and thus I could easily get out the second element with list[1].
How would I write such a regular expression?
I need to split the sting on single spaces ' ', but only if that single space is not surrounded by text in curly braces.
\s(?=[a-zA-Z{}]) gives me all the spaces and thus behaves exactly like ' '. How can I exclude the spaces in the curly braces?
re.search(r'(?<=} )\S+', str).group()