title: Regular Expression with Multiple Capture Groups
body: <p>I've been working on a regular expression to pick apart a bunch of text files that I need to parse into a database. My files are in the following format:</p>
  
  <pre><code>Lorem ipsum dolor&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;sit amet, consectetur adipiscing elit.
  
  Fusce lacinia sollicitudin lectus id eleifend. Phasellus.
  
  massa sapien, scelerisque in tincidunt et, porttitor eget ante.
  In iaculis justo vel quam rhoncus volutpat. Curabitur eros est,
  ultrices in elementum eget, venenatis eget mauris. Sed sollicitudin,
  nibh sed varius aliquet, neque odio porttitor risus, at sollicitudin
  
  lectus neque sit amet diam.
  Aliquam condimentum sapien eu
  tellus condimentum suscipit.
  Pellentesque in accumsan nunc.
  </code></pre>
  
  <p>I'm trying to come up with the following capture groups:</p>
  
  <ul>
  <li><code>Lorem ipsum dolor</code></li>
  <li><code>sit amet, consectetur adipiscing elit.</code></li>
  <li><code>Fusce lacinia sollicitudin lectus id eleifend. Phasellus.</code></li>
  <li><code>massa sapien, scelerisque in tincidunt et, porttitor eget ante.</code><br>
  <code>In iaculis justo vel quam rhoncus volutpat. Curabitur eros est,
  ultrices in elementum eget, venenatis eget mauris. Sed sollicitudin,
  nibh sed varius aliquet, neque odio porttitor risus, at sollicitudin</code></li>
  </ul>
  
  <p><strong>Notes:</strong>
  Everything after the multiline paragraph can be ignored. All of the groups can include letters, numbers, spaces and punctuation. I'm going to be doing some additional post-processing on the text using PHP.</p>
  
  <p>My last try to capture the first 2 parts, which was closer than my other attempts but still didn't work as intended was:</p>
  
  <pre><code>^((?:[a-zA-Z0-9!-~](?: (?! ))?)+?)(?: {2,})((?:[a-zA-Z0-9!-~](?: (?! ))?)+?)
  </code></pre>
  
  <p>I thought that this would start at the beginning of the file, capture everything up to the point where it encountered multiple spaces then grab the rest of the line.</p>