I would to grab whatever text is between "[email protected]" and "This e-mail (and attachment(s)) is confidential, proprietary," but dont know what is the best and most reliable way to do this. I thought regex but perhaps someone knows better. the number of empty lines may increase or decrease but those 2 strings will always have text between them. In this case the text is "testttinggg"
---------- Forwarded message ---------- From: person name Date: 2011/12/1 Subject: RE: this is a test subject To: [email protected]
This e-mail (and attachment(s)) is confidential, proprietary,
I tried to write
preg_match('/[email protected]\.com(.*?)This e-mail \(and attachment\(s\)\) is confidential,/', $wholeBody, $matches); echo $matches;
but it didnt work..
You're on the right way with your regex. You have to remember that the dot
. does not include linebreaks by default so you have to add the
You can try this. In capturegroup 1 you'll have the content (without the empty whitespaces and linebreaks)
(?<[email protected])\s*(.*?)\s*(?=This e-mail \(and attachment\(s\)\) is confidential, proprietary,)
You can see it in action here: http://regexr.com?2vc19
preg_match('/(?<[email protected])\s*(.*?)\s*(?=This e-mail \(and attachment\(s\)\) is confidential, proprietary,)/s', $message, $matches);