import re s="[var1]+[v/ar/2]^var3/var4"result = list(filter(None, re.split(r"(\[[^][]*])|[-+*/&,^%]", s)))print(result)
Standard input is empty
['[var1]', '[v/ar/2]', 'var3', 'var4']
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!