#!user/bin/env python #-*- coding:utf-8 -*- import re all=re.compile('(\d+\.\d+[eE][-+]?\d+|\d+\.\d+|[1-9]\d*|0[0-7]+|0x[0-9a-fA-F]+|[a-zA-Z_]\w*|>>|<<|::|->|\.|\+=|\-=|\*=|/=|%=|>=|<=|==|!=|&&|\|\||\+|\-|\*|/|=|>|<|!|^|%|~|\?|:|,|;|\(|\)|\[|\]|\{|\}|\'|\")') mth=all.findall('1+3.4-sin(6)-y*pi') print mth #输出结果 #['1','+','3.4','-','sin','(','6',')','-','y','*','pi']