Perl 正则表达式 获取邮件地址
我在 exim 日志中为这一行编写正则表达式时遇到了一些麻烦
1. 2011-05-12 11:30:26 1QKRHt-0001aD-Vd => mail <[email protected]> F=<[email protected]> bla bla
2. 2011-04-22 12:01:31 1QDCF0-0002ss-Nw => /var/mail/mail <[email protected]> F=<[email protected]> bla bla
3. 2011-05-12 11:29:01 1QKRGU-0001a5-Ok => [email protected] F=<[email protected]> bla bla
,我想将其放入变量 [电子邮件受保护] 在一个正则表达式中。我尝试使用这样的逻辑:在'F='之前找到最后一个字符串,用空格分隔,并且可以锁定在< >
你能帮我写一下这个逻辑吗?
ive got some trouble with writting regex for this lines in exim log
1. 2011-05-12 11:30:26 1QKRHt-0001aD-Vd => mail <[email protected]> F=<[email protected]> bla bla
2. 2011-04-22 12:01:31 1QDCF0-0002ss-Nw => /var/mail/mail <[email protected]> F=<[email protected]> bla bla
3. 2011-05-12 11:29:01 1QKRGU-0001a5-Ok => [email protected] F=<[email protected]> bla bla
and i want to put to variable this [email protected] in one regexp. ive tryed to use logic lile this: find last string before 'F=', seperated by whitespaces and can be locked in < >
Can you help me to write this logic?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用以下正则表达式:
然后最好使用 Mail-RFC822-Address perl 模块,因此完整代码可能是:
You can use the following regex:
And then it is a good idea to validate your match with Mail-RFC822-Address perl module, so the full code could be:
使用:
(?<= xxx )
语法是后向断言,而(?= xxx )
是先行断言。这不会检查电子邮件地址的有效性,只是提取该行的该部分。
Use:
The
(?<= xxx )
syntax is a lookbehind assertion, and the(?= xxx )
is a lookahead assertion.this will not check the validity of the e-mail address, just extract that part of the line.
正则表达式不是衡量标准, Email::Valid 才是。
Regex is not the measure, Email::Valid is.
这是一个电子邮件验证正则表达式
它将从任何地方提取电子邮件。
我希望这篇 RFC2822 帖子正确。
Here is a Email Validation Regex
It will extract an email from anywhere.
I hope this RFC2822 one posts correctly.