抓住括号内的元素

Adi*_*dia 3 python regex

如何抓取括号内的元素并将它们放在文件中?

我(你)你(你)他(他)她(她)

在此先感谢,Adia

eum*_*iro 5

import re

txt = 'me (I) you (You) him (He) her (She)'
words = re.findall('\((.+?)\)', txt)

# words returns: ['I', 'You', 'He', 'She']
with open('filename.txt', 'w') as out:
    out.write('\n'.join(words))

# file 'filename.txt' contains now:

I
You
He
She
Run Code Online (Sandbox Code Playgroud)