I wrote this regex that splits the expression 'res=3+x_sum*11' into lexemes
import re
print(re.findall('(\w+)(=)(\d+)(\*|\+)(\w+)(\*|\+)(\d+)', 'res=3+x_sum*11'))
with my output looking like this:
[('res', '=', '3', '+', 'x_sum', '*', '11')]
but i want re.findall to return a list of the lexemes and their tokens so that each lexeme is in its own group. That output should look like this:
[('', 'res', ''), ('', '', '='), ('3', '', ''), ('', '', '+'),
('', 'x_sum', ''), ('', '', '*'), ('11', '', '')]
How do i get re.findall to return an output like that