import rerx = r"(\d+)|([^\W\d]+)|(\W)"s = "res=3+x_sum*11"print(re.findall(rx, s))
Standard input is empty
[('', 'res', ''), ('', '', '='), ('3', '', ''), ('', '', '+'), ('', 'x_sum', ''), ('', '', '*'), ('11', '', '')]
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!