I have a querystring like this:
s = 'word1 AND word2 word3 OR "word4 word5" OR word6 AND word7 word8'
I need to find all words or phrases within OR and AND, so the results will be a list like this (preferably without the spaces between AND/OR and the word/phrase):
l = ['word1', 'word2 word3', '"word4 word5"', 'word6', 'word7 word8']
I’ve tried messing around with regular expressions but could’t find a way to do this.
Thanks for the help.
If you want to use regexps, re.split should do it:
If you need a bigger hammer, you could check out something like pyparsing:
http://pyparsing.wikispaces.com/file/view/searchparser.py