title: Parse email header from text using PCRE regular expression
body: <p>I need to parse (split) a text file containing emails exported from Outlook.
  I am splitting it using <code>preg_split</code> with <code>PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE</code></p>
  
  <p>My goal is to capture message header section with the regular expression, i.e. starting from "From:" line and ending with the blank line before message body. </p>
  
  <p>Constraints: </p>
  
  <ul>
  <li>Multilingual field names expected</li>
  <li>Number of header fields varies (CC, BCC, Attachments)</li>
  <li>Some fields may be on more than one line (To, CC, BCC, Subject, Attachments)</li>
  </ul>
  
  <p>the text file is pre-treated: replace multiple spaces and tabs with single space, replace leading and trailing spaces.</p>
  
  <p>I have been at it whole day, cannot get the last part to work. It does work on [gskinner regex testing page]: <a href="http://regexr.com?36v27" rel="nofollow">http://regexr.com?36v27</a> , but not in php.</p>
  
  <p>Subject:</p>
  
  <pre><code>From: Black, Jack (LA)
  Sent: Monday, October 28, 2013 6:36 PM
  To: George, Jackson (London); DCS.CC.DARWIN (Australia)
  Cc: Bar, Foo (Istanbul); Ex, Reg (Istanbul); Smith, John (Istanbul); Rambo,
  John J. (Gaziantep); Matrix, John (Phuket)
  Subject: RE: PREVENTIVE AND CORRECTIVE ACTIONS / FOOBAR
  
  Dear George,
  
  venenatis imperdiet quam. Proin a egestas nunc, et mattis elit. In hac habitasse platea dictumst. Nulla dolor nibh, tempus ut neque eu, tempus fermentum mauris. Mauris nec ipsum nec sapien commodo scelerisque ut eu urna. Pellentesque eu neque in enim adipiscing faucibus. Sed interdum arcu et sem mollis iaculis. Duis euismod laoreet ligula lacinia dapibus. Vestibulum ullamcorper malesuada metus at malesuada. 
  
   Nullam enim elit, auctor vehicula orci eget, imperdiet feugiat odio. Etiam dapibus sagittis sem a varius. Nulla sit amet convallis mi, sit amet rutrum ipsum. In libero lectus, mattis at dui eu.
  
  Thank you and best regards,
  
  Jack B. Black (Mr)
  Operations Manager (GGD)
  FU Supervisor (R34, R57)
  
  Phone: +1112212212 (local 1111)
  Mobile: +12 121.111.11.12
  
  From: George, Jackson (UK)
  Sent: Monday, October 28, 2013 5:57 PM
  To: DCS.CC.DARWIN (Australia)
  Bar, Foo (Istanbul); Ex, Reg (Istanbul); Smith, John (Istanbul); Rambo,
  John J. (Gaziantep); Matrix, John (Phuket)
  Subject: PREVENTIVE AND CORRECTIVE ACTIONS / FOOBAR
  
  Dear Colleagues,
  
  ermentum. Duis ipsum quam, bibendum a risus nec, tincidunt fringilla lectus. Nunc vel dictum massa, et cursus nunc. Mauris tincidunt felis eget justo congue volutpat. Nulla condimentum accumsan elementum. Integer commodo, lorem eu pharetra suscipit, ligula.
  
  Best Regards.
  
  SDFD srfgGD
  Field coordinator (GGD)
  Customer Representative
  
  sds dfsd sdfgsef sdfsd
  sgzdfgdfg fgfg gdfg
  Footer text etc
  sdfdfdf dfgsdfgsdfgsdfg
  Phone : +90 212 368 40 00 (ext:3814)
  </code></pre>
  
  <p>Regex:</p>
  
  <pre><code>preg_match(
                   '/                         # delimiter
                  (                           # capturing group start
                  [\ A-Z][a-z]+:.+\(.+\)\R    # From: field
                  [A-Z][a-z]+:.+\R            # Sent: fields
                  [A-Z][a-z]+:.+\R            # To: field (1st line)
                  (?:.+\R)+              # any additional header lines, before blank line (To, CC, BCC, Subject, Attachments)
                  )                           # capturing group end
                  # delimiter + modifiers /x',$text_clean, $matches);
          echo '&lt;b&gt;Matches: '.count($matches).'&lt;/b&gt;';
          print_r($matches);   
  </code></pre>
  
  <p>I am having problem getting additional header lines:</p>
  
  <pre><code>(?:.+\R)+              # any additional header lines...
  </code></pre>
  
  <p>Any help is appreciated</p>