开发者

Sent mail date regular expression

开发者 https://www.devze.com 2023-03-13 22:14 出处:网络
when replying on an email usually the mail client adds the sent date of the email before the original mail

when replying on an email usually the mail client adds the sent date of the email before the original mail something like the following:

my reply
On Fri, 2011-06-17 at 12:33 -0400, friendly user wrote:
> Reply ABOVE THIS LINE
and here is the original message.

and I want to make a regular expression to match the second & third lines开发者_JAVA技巧 and get it's beginning index, so i can substring from 0 to that date.


A regular expression do match the date would be (Mon|Tue|Wed|Thu|Fri|Sat|Sun), \d{4}-\d{2}-\d{2} at \d{2}:\d{2} (-)?\d{4}(\r\n|\r|\n)> Reply ABOVE THIS LINE. I don't know Java but I imagine there is a RegEx match function which will return the character position of the match, if it finds one. Otherwise the hack is to add a .*$ to the end of the RegEx and use the replace function to replace the date and everything after it with nothing, leaving you with just the part you want.


I'm no regex wizard, but You'd need something similar to:

^(On ).{3}, (19|20)\d\d-\d\d-\d\d at \d\d:\d\d -\d\d\d\d,

Obviously its not as clean in validating valid times and dates but I'm assuming your email server isn't spitting out invalids.


i tried the following and it works:

On.*?wrote:(\r\n|\r|\n)> Reply ABOVE THIS LINE
0

精彩评论

暂无评论...
验证码 换一张
取 消