title: Java regular expression longest match
body: <p>I am having a problem with a generic regex that matches (sort of) a typical string of the form</p>
  
  <pre><code>... "field1" "field2" "field3" "field4" ...
  </code></pre>
  
  <p>What I want to do is, of course, get each of these fields separately. Because the fields can contain any character, I am using a "catch-all" regex of the form</p>
  
  <pre><code>... \"(.*?)\" +\"(.*?)\" +\"(.*?)\" +\"(.*?)\" + ...
  </code></pre>
  
  <p>The problem is, instead of producing 4 different groups, Java gives me just one, which is merges those 4 above, i.e. I get a single field:</p>
  
  <pre><code>field1" "field2" "field3" "field4
  </code></pre>
  
  <p>instead of</p>
  
  <pre><code>field1
  field2
  field3
  field4
  </code></pre>
  
  <p>I have even tried doing things like \"([^\"]*)\" for each of the fields, but the result is the same.</p>
  
  <p>How could I get these 4 fields separately?</p>