Python 11 提取括号中间的内容

原文:https://blog.csdn.net/your_answer/article/details/80456550

import re
 
string = 'abe(ac)ad)'
p1 = re.compile(r'[(](.*?)[)]', re.S)  #最小匹配
p2 = re.compile(r'[(](.*)[)]', re.S)   #贪婪匹配
print(re.findall(p1, string))
print(re.findall(p2, string))

功能:获取括号里面的字符串

import re
import numpy
 
string = 'abe(ac)ad)'
p1 = re.compile(r'[(](.*?)[)]', re.S) 
arr = re.findall(p1, string)
print(arr[0])
原文地址:https://www.cnblogs.com/guxingy/p/11213210.html