a non regex method using string methods....
>>> z = '346 + 324 - 368' >>> x = z.maketrans('+-','..') >>> x {43: 46, 45: 46} >>> y = z.translate(x).split('.') >>> y ['346 ', ' 324 ', ' 368']of course at this point its a list and each string is not separate by one single space
>>> a = list(map(str.strip, y)) >>> a ['346', '324', '368'] >>> ' '.join(a) '346 324 368'This would not matter of exact format as something like this
z = '346 + 324 - 368 - 368 + 368 + 368 -45 -56- 368'would still split to this
346 324 368 368 368 368 45 56 368Using python3.x otherwise you have to import string and convert maketrans line to.... string.maketrans('+-','..')
Recommended Tutorials: