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])

 

posted @ 2019-07-19 14:48  古兴越  阅读(5027)  评论(0编辑  收藏  举报