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[1];

but it didnt work..

Answers


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

Update:

preg_match('/(?<=Nadal@gmail.com)\s*(.*?)\s*(?=This e-mail \(and attachment\(s\)\) is confidential, proprietary,)/s', $message, $matches);

http://codepad.viper-7.com/C6Mxqd


Need Your Help

Which Postgres value should I use in Django's DATABASE_ENGINE?

django postgresql psycopg2

It's my first time using PostgreSQL 8.4.2 with Django(I have always used MySQL or sqlite3 in the past). Which value should I use for DATABASE_ENGINE in settings.py, postgresql_psycopg2 or postgres...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.