假设我有一个看起来像这样的字符串:
test = 'this is a (meh) sentence that uses (random bits of meh2) and (this is silly)'
我希望提取括号内仅包含单词“meh”的文本。
使用非贪婪正则表达式匹配括号内的任何内容:
re.findall(r'\((.*?)\)', test)
返回
['meh', 'random bits of meh2', 'this is silly']
尝试只包括第一个和第二个内容:
re.findall(r'\((.*meh.*?)\)', test)
返回
['meh) sentence that uses (random bits of meh2']
I want a regex to return only
['meh', 'random bits of meh2']
请问有人能帮忙吗?谢谢!
.*
非贪婪。 - internet_user\((.*?meh.*?)\)
- zzxyz