取出字符串中括号引号的所有部分,会存为列表
import re str = "fdic['LoanCapital']/dic['LoanPeriod']" print(re.findall(r"\['(\w+)'\]",str,re.M)) #输出
['LoanCapital', 'LoanPeriod']
参考:
https://www.cnblogs.com/dreamer-fish/p/5282679.html
https://www.cnblogs.com/rj81/p/5933838.html
另re.split也可以用正则按多个字符拆分re.split('[+-*/]',str)