I have a string that I want to split by certain special characters. But I don't want to split anything inside square brackets. How can I set up my regex to ignore cases inside square brackets?
formula = '[var1]+[v/ar/2]^var3/var4' #assume no spaces in the formula
re.split('[-+*/&,^%]',formula) #produces ['[var1]', '[v', 'ar', '2]', 'var3', 'var4']
Desired output:
['[var1]', '[v/ar/2]', 'var3', 'var4']
I think I need to use some fancy negative lookbehind and negative lookahead, but I haven't found a working combination yet.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…