?
Solved

parsing previous body

Posted on 2013-02-04
4
Medium Priority
?
164 Views
Last Modified: 2013-02-04
words words words<br>words.

On Mon, Jan 2, 2012 at 8:48 PM,
PREVIOUS BODY

Open in new window



words words words<br>words.

On Wed, Feb 12, 2012 at 10:48 PM,
PREVIOUS BODY

Open in new window


I am parsing gmail bodys

These are examples of the gmail body where the body ends and the previous body is displayed

I do not want to see the previous body, so I would like to strip everything after and including

[new line][new line]
On[space][day of week][comma][space][month][space][day of month][comma][space][year][space]at[time of day][space][am or pm]
0
Comment
Question by:rgb192
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 35

Expert Comment

by:Terry Woods
ID: 38853182
A regex for the pattern you're describing is:
\n\nOn \w{3}, \w{3} \d\d?, \d{4} at \d\d?:\d\d [AP]M

Open in new window

You missed a space before the time of day, so I've added it. You may like to add the comma to the end too for completeness.

In some cases I find there are also line feed characters in between newlines. They can be accounted for (without being required) like this:
\r?\n\r?\nOn \w{3}, \w{3} \d\d?, \d{4} at \d\d?:\d\d [AP]M

Open in new window

0
 

Author Comment

by:rgb192
ID: 38853197
$body='
words words words<br>words.

On Mon, Jan 2, 2012 at 8:48 PM,
PREVIOUS BODY
 ';

Open in new window


how can I write $smaller_body=replace(pattern,$body)
0
 
LVL 35

Accepted Solution

by:
Terry Woods earned 2000 total points
ID: 38853279
Try this:

$smaller_body=preg_replace("#^(.*?)\r?\n\r?\nOn \w{3}, \w{3} \d\d?, \d{4} at \d\d?:\d\d [AP]M.*#s","$1",$body)

Open in new window


(update: fixed bug)
0
 

Author Closing Comment

by:rgb192
ID: 38853501
I have a related question for html gmail body

http://www.experts-exchange.com/Programming/Languages/Regular_Expressions/Q_28020015.html

works thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
We are witnesses that everyone is saying that our children shouldn't "play" with a technology because it is dangerous. This article is going to prove that they are wrong.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question