开发者

Sent mail date regular expression

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜