Solved

parsing previous body

Posted on 2013-02-04
4
156 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
  • 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 500 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now