RegEx to match time in “Received: by” e-mail header

雨燕双飞 提交于 2019-12-06 20:06:22

Amended version of Eugene's regex;

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

This version uses non-capturing grouping, and restricts the acceptable time to 07:00:00 to 21:59:59. It assumes the time format is valid - in theory it would pass a time of 10:99:99, but I'm assuming you won't see those.

Fixed for you to work using http://gskinner.com/RegExr/, still largely suboptimal. Tell if you want to go into this further.

\bReceived: 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]\b
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!