【发布时间】:2021-09-29 10:17:41
【问题描述】:
我有一个字符串如下:
" I wanted my friends (he), (she), (they) around"
我想获得一个包含["he", "she", "they"] 的列表。
以下是我的代码:
copy = " (he), (she), (they)"
x = re.findall(r'^{.}$', copy)
但这给了我一个空列表作为输出。
我还尝试了以下方法:
import re
copy = '{he},{she}, {they}'
x = re.findall(r'\{([^]]*)\}', copy)
print(x)
但在这种情况下,输出是:
['he},{she}, {they']
【问题讨论】: