title: Regex to extract base64 encoded parts from email body from php imap
body: <p>I have the following sting below, It's an e-mail body and I want to extract only the <code>base64</code> encoded files from it in PHP. I was thinking I could use regex to just extract the base64 parts so I could then decode them e.g.</p>
  
  <pre><code>preg_match('/Content-Transfer-Encoding: base64\s(.*)\sContent-Type:/', $message['body'], $matches);
  
  echo base64_decode($matches[0]);
  </code></pre>
  
  <p>However I'm not getting any matches as I don't think my regex is working. Ideally I want to capture each part which starts after 'Content-Transfer-Encoding:' and ends with another 'Content-Type:' part starting. My question is, how do I regex all the base64 parts? e.g.</p>
  
  <p><code>Content-Transfer-Encoding</code>: (capture this part as a match) Content-Type: </p>
  
  <p>Below is part of the message and the full string can be found here:</p>
  
  <blockquote>
    <p><a href="http://pastebin.com/A5XXnSaT" rel="nofollow">http://pastebin.com/A5XXnSaT</a></p>
    
    <p>--_004_D16F6E4A2986D34F9D752E3564EAC46F359618EFAPP1197ghakfplc_ Content-Type: multipart/alternative; boundary="_000_D16F6E4A2986D34F9D752E3564EAC46F359618EFAPP1197ghakfplc_" --_000_D16F6E4A2986D34F9D752E3564EAC46F359618EFAPP1197ghakfplc_ Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: base64 SGksIFBsZWFzZSBmaW5kIHRoZSBhdHRhY2hlZCBQRlMgZXJyb3IgUmVwb3J0DQoKLS0tLS0tLS0t LQpCJlEgcGxjClJlZ2lzdGVyZWQgT2ZmaWNlOiBCJlEgSG91c2UsIENoZXN0bnV0IEF2ZW51ZSwg Q2hhbmRsZXJzIEZvcmQsIEVhc3RsZWlnaCwgSGFtcHNoaXJlLCBTTzUzIDNMRQpCdXkgT25saW5l IE5PVyBhdCB3d3cuZGl5LmNvbSBvciBmb2xsb3cgQiZRIG9uIEZhY2Vib29rIHd3dy5mYWNlYm9v... </p>
  </blockquote>