0

I want to extract text between these brackets {}. The code looks like this:

s = '{asdf=5;iwantthis123jasd}hhhhh{gggg}'

The desired outcome would look like this:

asdf=5;iwantthis123jasd, gggg

However, when I use this code

import re
s = '{asdf=5;iwantthis123jasd}hhhhh{gggg}'
result = re.search("{(.*)}", s)
print(result.group(1))

The output is the following:

asdf=5;iwantthis123jasd}hhhhh{gggg

So the code catches only first and last bractet. How to do it so it catches the first closing bracket it finds and then do the same for the next one?

Thanks :)

Aleksandra
  • 27
  • 4
  • `result = re.findall(r"{(.*?)}", s)` or `result = re.findall(r"{([^{}]*)}", s)`. Also, see [this regex "quickie"](https://www.youtube.com/watch?v=qxXAGO31fHA). – Wiktor Stribiżew Jul 27 '21 at 13:23

0 Answers0