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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM