fork download
  1. import re
  2.  
  3. regex = r"[+=]|(?=(?<!^)-)"
  4. strings = [
  5. '-9x+5x-2-4x+5',
  6. '-3x-5x+2=9x-9'
  7. ];
  8.  
  9. for str in strings:
  10. print(re.split(regex, str))
  11.  
Success #stdin #stdout 0.02s 9520KB
stdin
Standard input is empty
stdout
['-9x', '5x', '-2', '-4x', '5']
['-3x', '-5x', '2', '9x', '-9']