ravi ravi
ravi ravi

Reputation: 55

regular expression to remove original message from reply mail using in java?

In my forum, users can reply through email. I am handling mails from their reply. When they are replying the original message getting appended. I want to get only the reply message not the original message.

I have to write regular expression for gmail & hotmail.

I written regex for gmail as follows :

\n.*wrote:(?s).*--End of Post--

It is removing the original message except date. I want to remove the date also.

before removing the original message :

 hi 33

 On Tue, May 11, 2010 at 4:18 PM, Mmmmm, Rrrrr
 <[email protected]>wrote:

  The following update has been posted to this discussion:
  ----------------------------------------------------------------------
  test as user 222
  ----------------------------------------------------------------------
  [$MESSAGE_SIGNATURE_HEADER$]



  --End of Post--

When I use the above regex it is filtering as follows :

 hi 33

 On Tue, May 11, 2010 at 4:18 PM, Mmmmm, Rrrrr

Here i want only the actual message 'hi 33' not that date. How can I filter the date using above regex?

Also I need regex for Hotmail also.

I appreciate for any reply. Thanks in advance.

Upvotes: 0

Views: 2371

Answers (2)

ravi ravi
ravi ravi

Reputation: 55

I got it. To skip new lines i modified in this way ....

On\s+\w+,\s+\w+\s+\d+,\s+\d+\s+at\s+\d+:\d+\s+\w+,\s+\w+,\s+\w+(?s).?wrote:.\n(?s).*--End of Post--

Upvotes: 0

PeterM
PeterM

Reputation: 1198

Try this one (this will match everything that should be removed):

On\s+\w+,\s+\w+\s+\d+,\s+\d+\s+at\s+\d+:\d+\s+\w+,.*?wrote:.*?--End of Post--

Or the simpler version:

On.*?wrote:.*?--End of Post--

Upvotes: 1

Related Questions