what Regex works for this?
I would to grab whatever text is between "Nadal@gmail.com" 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: Nadal@gmail.com testingggggg This e-mail (and attachment(s)) is confidential, proprietary,
I tried to write
preg_match('/nadal@gmail\.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 DOTALL modifier.
You can try this. In capturegroup 1 you'll have the content (without the empty whitespaces and linebreaks)
(?<=Nadal@gmail.com)\s*(.*?)\s*(?=This e-mail \(and attachment\(s\)\) is confidential, proprietary,)
You can see it in action here: http://regexr.com?2vc19
preg_match('/(?<=Nadal@gmail.com)\s*(.*?)\s*(?=This e-mail \(and attachment\(s\)\) is confidential, proprietary,)/s', $message, $matches);