As an exercise I was trying to come up with a regex to evaluate simple algebra like
q = \'23 * 345 - 123+65\'
From here I want to get \'23\', \
Simply try this.
import re q = '23 * 345 - 123+65' regexparse = r'(\d+)|[-+*/]' for i in re.finditer(regexparse, q): print i.group(0)
output:
23 * 345 - 123 + 65