English 中文(简体)
在“ 收到: by” 电子邮件信头中匹配时间的 RegEx
原标题:RegEx to match time in "Received: by" e-mail header

在我的网站所在的共享主机上,我有一个电子邮件转发器,将信息作为短信发到我的手机上。 但最近,它有点失控。

我希望,利用小组内的“用户级过滤” ,我可以设置一个基于RegEx的过滤器,仅在7:00至22:00之间将电子邮件转发到我的手机。

此过滤器将与下列电子邮件信头匹配, 通常会发生于2-3行, 进入电文源 :

Received: by 99.99.99.99 with SMTP id XyXyXyXyXyXyXy;
        Tue, 15 May 2012 01:22:33

......这就是我希望它的工作方式:

Received: by (ANY IP) with (ANYTHING) id (ANYTHING);
        (Sun|Mon|Tue|Wed|Thu|Fri|Sat), (ANY DATE/MONTH/YEAR) (RegEx magic to match time?)

当比赛成功时( 例如, 如果时间在 07: 00 到 22: 00 ), 信件就会发到我的手机上, 否则它不会起作用 。 ( 这与 RegEx 本身无关, 当然) 。

我是一个普通表达式 n00b, 但设计了以下(不工作的)RegEx, 不知道我有多接近或远离它的工作:

Received: by (.*) with [a-Z] id (.*)(Sun|Mon|Tue|Weds|Thu|Fri|Sat),(.*)[0-2][2-7]:[0-2][0-9]:[0-2][0-9]si

任何想法、建议或创造性解决办法?我的东道服务告诉我,小组中的RegEx必须采用PERL格式。

最佳回答

经修正的Eugene s regex版本;

/Received: by .*?;s*(?:Sun|Mon|Tue|Weds|Thu|Fri|Sat),s*d+s+w+s+d+s+(?:0[789]|1d|2[01]):dd:dd/

本版本使用非控制分组, 并将可接受的时间限制在 07: 00: 00 到 21: 59: 59 。 它假定时间格式是有效的- 从理论上讲, 它会超过 10: 99: 99, 但我假设你看不到这些 。

问题回答

您使用< a href=> 固定工作, 使用 < a href=> http://gskinner.com/regExr/" rel="nofollow" > http://gskinner.com/regExr/ , 基本上仍然不够理想。 告诉您是否想进一步讨论这个问题 。

Received: by (.*) with w+ id (.*);s*(Sun|Mon|Tue|Weds|Thu|Fri|Sat),s*(d+s+w+s+d+)s+[0-2][0-9]:[0-5][0-9]:[0-5][0-9]




相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签