title: What is a good way to error check strings for certain terms in Python (with or without Regex)?
body: <p>I am dealing with some boolean queries with the use of "AND", "OR", or "NOT" in a IR system, and was wondering how I would check for invalid queries. For example, these queries would be <strong>invalid:</strong></p>
  
  <blockquote>
    <p>"tom OR", "tom NOT", "beans AND OR beans", "NOT AND mad", "(cat AND
    dog" [since ( incomplete]), etc...</p>
  </blockquote>
  
  <p>These terms are invalid because a boolean query needs 2 "words" on each side (unless we have NOT). Any tips for error checking for these things? I am pretty lost and would like a direction or something.</p>
  
  <p>Thanks!</p>