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

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

阅读 33.2k
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 就是括号中的内容

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题