title: Split a String at space, but only outside of quotes
body: <p>i would like to split a String at every space character, but split the quoted parts out seperately.
  I tried using the regex pattern </p>
  
  <pre><code>",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)" 
  </code></pre>
  
  <p>and replaced the <code>commas ","</code> with <code>space " " or "\\s"</code> </p>
  
  <pre><code>"\\s(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"
  </code></pre>
  
  <p>and it works fine in the following example: <br>
  Input: <code>"foo \"bar foo\" bar"</code> <br>
  Output:<code>[foo, "bar foo", bar]</code></p>
  
  <p>but if you remove the space before and after the inner quotes, you get the following: <br>
  Input: <code>"bar foo\"bar foo\"bar foo"</code> <br>
  Output: <code>["bar", "foo\"bar foo\"bar", "foo"]</code><br>
  Desired Output: <code>["bar", "foo", "\"bar foo\"", "bar", "foo"]</code></p>
  
  <p>@the-fourth-bird kindly created the following regex</p>
  
  <pre><code>"(?:\\h|(?=\")|(?&lt;=\"))(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"
  </code></pre>
  
  <p>which works in the above situation, but fails in the case of spaces:<br>
  Input: <code>"foo \"bar foo\" bar"</code><br>
  Output: <code>["foo", "", "\"bar foo\"", "bar"]</code><br>
  Desired Output: <code>["food", "\"bar foo\"", "bar"]</code></p>
  
  <p>This problem can be solved by just removing empty strings from the array, but is there also a way to solve it in the regex?</p>
  
  <p>Thanks a lot for the help!</p>