python正则表达式提取小括号里面的字符串

python怎么用正则表达式提取出小括号里面的内容
比如从abc(hello)casdf提取出hello

阅读 33.4k
3 个回答
import re

s = "abc(hello)casdf"

m = re.match(".*\((.*)\).*", s)
print(m.group(1))
import re
s = "abc(hello)casdf(world)"
re.findall(r"[(](.*?)[)]",s)

#['hello', 'world']

/(.*?)/

$1 就是括号中的内容

推荐问题