fork(1) download
  1. from pyparsing import delimitedList, Word, alphas, Combine
  2.  
  3. str1 = Combine(Word(alphas) + "+" + Word(alphas)) # "x+y"
  4. str2 = Combine(Word(alphas) + "++") # "c++"
  5. str3 = Word(alphas) # "z"
  6.  
  7. strs = str1 | str2 | str3
  8.  
  9. f = delimitedList(strs, "+")
  10. print(f.parseString("x+y+c+++z+x+z+++x"))
Success #stdin #stdout 0.07s 11056KB
stdin
Standard input is empty
stdout
['x+y', 'c++', 'z+x', 'z++', 'x']