fork(2) download
  1. import re
  2.  
  3. string = "section_category_name = 'computer and equipment expense' and date >= 2015-01-01 and date <= 2015-03-31"
  4.  
  5. lexer = re.compile(r"'[^']*'|[^ ]+|$")
  6.  
  7. results = []
  8.  
  9. buff = []
  10. for match in lexer.finditer(string):
  11. token = match.group(0) # group 0 is the entire matching string
  12.  
  13. if token in ('and', ''):
  14. results.append(' '.join(buff))
  15. buff = []
  16. else:
  17. buff.append(token)
  18.  
  19. 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']