Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

parsing previous body

Posted on 2013-02-04
4
Medium Priority
?
168 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

610 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