python – 提取模式中的单词

我有以下字符串

[(net, asset), (amount, asset), (connect, asset), (net, asset), (check, asset), (service, asset), (adapt, asset)] | [(part, asset)] 

我想只提取开括号之后的第一个单词.我的输出应该是 –

net amount connect net check service adapt part

数据

[(net, asset), (amount, asset), (connect, asset), (net, asset), (check, asset), (service, asset), (adapt, asset)] | [(part, asset)]

我尝试了以下内容.

p=re.compile("'('(.*)','")
result = p.search(data)
result.group(1)

但这种模式匹配不起作用.请帮忙

最佳答案 正则表达式的分析在这里:
https://regex101.com/r/kAXpNA/1.

re.findall('\((.*?),', '[(net, asset), (amount, asset), (connect, asset), (net, asset), (check, asset), (service, asset), (adapt, asset)] | [(part, asset)]')
#['net', 'amount', 'connect', 'net', 'check', 'service', 'adapt', 'part']
点赞