title: Decomposing a string into words separared by spaces, ignoring spaces within quoted strings, and considering ( and ) as words
body: <p>How can I explode the following string:</p>
  <pre><code>+test +word any -sample (+toto +titi &quot;generic test&quot;) -column:&quot;test this&quot; (+data id:1234)
  </code></pre>
  <p>into</p>
  <pre><code>Array('+test', '+word', 'any', '-sample', '(', '+toto', '+titi', '&quot;generic test&quot;', ')', '-column:&quot;test this&quot;', '(', '+data', 'id:1234', ')')
  </code></pre>
  <p>I would like to extend the boolean fulltext search SQL query, adding the feature to specify specific columns using the notation <code>column:value</code> or <code>column:&quot;valueA value B&quot;</code>.</p>
  <p>How can I do this using <code>preg_match_all($regexp, $query, $result)</code>, i.e., what is the correct regular expression to use?</p>
  <p>Or more generally, what would be the most appropriate regular expression to decompose a string into words not containing spaces, where spaces within text between quotes is not considered spaces, for the sake of defining a word, and <code>(</code> and <code>)</code> are considered words, independent of being surrounded by spaces. For example <code>xxx&quot;yyy zzz&quot;</code> should be considered a single world. And <code>(aaa)</code> should be three words <code>(</code>, <code>aaa</code> and <code>)</code>.</p>
  <p>I have tried something like <code>/&quot;(?:\\\\.|[^\\\\&quot;])*&quot;|\S+/</code>, but with limited/no success.</p>
  <p>Can anybody help?</p>