title: How to add quotation marks to substrings of interest only?
body: <p>I have written a parser that is able to attribute information from a string. I don't know how to add quotation marks around substrings of interest. Let me illustrate:</p>
  
  <p>I've got this message:</p>
  
  <pre><code>message = 'I have two variables: -mass: 12 --vel= 18 OR this is just another descriptor AND that new thing OR that newfangled thing' 
  </code></pre>
  
  <p>That I need to add quotation marks around specific substrings (that follow boolean operators) like this:</p>
  
  <pre><code>message = 'I have two variables: -mass: 12 --vel= 18 OR "this is just another descriptor" AND "that new thing" OR "that newfangled thing"' 
  </code></pre>
  
  <p>I've done this:</p>
  
  <pre><code>attributes = ['OR', 'AND', 'NOT']
  message = 'I have two variables: -mass: 12 --vel= 18 OR this is just another descriptor AND that new thing OR that new fangled thing'
  for attribute in attributes:
          modified_attribute = ' '+attribute+' '
          message = modified_attribute.join('"{}"'.format(s.strip()) for s in message.split(attribute))
          if attributes.index(attribute)&gt;0: message = message[1:-1]
  
  print(message)
  </code></pre>
  
  <p>However, it returns this, which is not what I want:</p>
  
  <pre><code>"I have two variables: -mass: 12 --vel= 18" OR "this is just another descriptor" AND "that new thing" OR "that new fangled thing"
  </code></pre>
  
  <p>The above should have quotation marks around the first sentence, as it was not preceded by a boolean operator. What do I do?</p>
  
  <p>EDIT:
  I am looking for a scalable solution which can be used to quote any number of substrings within a string.</p>