fork download
  1. import re
  2. from itertools import groupby
  3.  
  4. string = "section_category_name = 'computer and equipment expense' and date >= 2015-01-01 and date <= 2015-03-31"
  5.  
  6. lexer = re.compile(r"'[^']*'|[^\s']+")
  7. grouping = groupby(lexer.findall(string), lambda x: x == 'and')
  8. results = [ ' '.join(g) for k, g in grouping if not k ]
  9.  
  10. print results
Success #stdin #stdout 0.01s 8968KB
stdin
Standard input is empty
stdout
["section_category_name = 'computer and equipment expense'", 'date >= 2015-01-01', 'date <= 2015-03-31']