Python 正则表达式查找/拆分包含末尾括号的精确单词/excel 公式

Python Regex find / split exact word including parentheses at the end / excel formula

我对正则表达式的最后部分有困难,这是我尝试将字符串拆分为

import re

s1 = 'A+" hello"+B'
s2 = 'A+(100-20)'
s3 = 'A-B+TODAY()-100'

print (re.split('([A-Z]+|["].?["]|[\=\+\-\%\*\^]|\bTODAY\(\)\b)', s1))
#expected ['', 'A', '', '+', '" hello"', '+', '', 'B', '']
#actual   ['', 'A', '', '+', '" hello"', '+', '', 'B', '']

print (re.split('([A-Z]+|["].?["]|[\=\+\-\%\*\^]|\bTODAY\(\)\b)', s2))
#expected ['', 'A', '', '+', '(', '100', '-', '20', ')']
#actual   ['', 'A', '', '+', '(100', '-', '20)']

print (re.split('([A-Z]+|["].?["]|[\=\+\-\%\*\^]|\bTODAY\(\)\b)', s3))
#expected ['', 'A', '', '-', '', 'B', '', '+', '', 'TODAY', '()', '-', '100']
#actual   ['', 'A', '', '-', '', 'B', '', '+', '', 'TODAY()', '-', '100']

编辑:更正,意思是用双引号括起任何长度的字符

匹配 TODAY() 的模式应该是第一选择

import re    
print (re.split('(TODAY\(\)|[A-Z]+|["].?["]|[\=\+\-\%\*\^])','A-B+TODAY()'))