如果不存在空格或任何其他运算符,则没有regex但会中断。expr = "20 - 5 - 4 + 10 + 4"tokens = expr.split()if tokens[0].isnumeric():tokens = ['+'] + tokenstokens = [''.join(t) for t in zip(*[iter(tokens)]*2)]pos = [t.strip('+') for t in tokens if '+' in t]neg = [t.strip('-') for t in tokens if '-' in t]或按照@Sayse建议:tokens = expr.replace('- ','-').replace('+ ','+').split()pos = [t.strip('+') for t in tokens if '-' not in t]neg = [t.strip('-') for t in tokens if '-' in t]