1

我在这些汇总的电子邮件中有一堆姓名和电子邮件地址,我想摆脱除First Last <email@domain.com>整个文档之外的所有内容。基本上我有...

From: Name Wood <email@gmail.com>
Subject: Yelp entries for iPod contest
Date: April 20, 2012 12:51:07 PM EDT
To: email@domain.cc

Have had a great experience with .... My Son ... is currently almost a year into treatment. Dr. ... is great! Very informative and always updates us on progress and we have our regular visits. The ... buck program is a great incentive which they've implemented to help kids take care of their teeth/braces. They also offer payment programs which help for those of us that need a structured payment option. Wouldn't take my kids anywhere else. Thanks Dr. ... and staff
Text for 1, 2, and 3 entries to Yelp
Hope ... wins!!
Begin forwarded message:

From: Name Wood <email@gmail.com>
Subject: reviews 2 and 3
Date: April 20, 2012 12:44:26 PM EDT
To: email@domain.cc

Have had a great experience with ... Orthodontics. My Son ... is currently almost a year into treatment. Dr. ... is great! Very informative and always updates us on progress and we have our regular visits. The ... buck program is a great incentive which they've implemented to help kids take care of their teeth/braces. They also offer payment programs which help for those of us that need a structured payment option. Wouldn't take my kids anywhere else. Thanks Dr. ... and staff
Have had a great experience with...

我只想匹配...

Name Wood <email@gmail.com>
Name Wood <email@gmail.com>

从这个文本。所以基本上我想匹配单词"From: "plus之后的下两个单词,"<"+email address+">"不包括单词"From: "。我从研究中了解到,这是一个消极的前瞻性(我认为)搜索两个完整的单词(不知何故使用{0,2}),然后是一个从一个<字符到另一个字符的电子邮件地址>

4

3 回答 3

0

你可以这样做:

/(?:From: )(.*)/g
于 2012-05-02T21:49:34.197 回答
0

此正则表达式将找到您要查找的内容:

(?<=From:)\s*[^<]+<[^>]+>

但是,从您的问题来看,您将如何处理它有点不清楚。匹配的文本可能应该被放入一个或多个组中,以便您可以提取所需的文本。(姓名在一个组中?电子邮件在一个单独的组中?还是两者都在一起?)您还没有说您想用它做什么,所以您必须提供更多信息。以上是最简单的情况。

解释:

(?<=From:)   # positive lookbehind to find "From:"
\s*          # optional whitespace
[^<]+<       # everything up to the first '<' (the name)
[^>]+>       # everything up to the '>' (the email)
于 2012-05-02T21:49:43.857 回答
0

如果您想删除除姓名和电子邮件之外的所有内容。
修饰符's'(点包括换行符),
两个正则表达式的全局查找和替换是$1\n

这更快,但会在成功时留下额外的换行符。

Find .*?From:[^\S\n]*([^<\n]+<[^>\n]*\@[^>\n]*>)|.*$

这比较慢(使用前瞻),但不会留下额外的换行符。

Find  .*?From:[^\S\n]*([^<\n]+<[^>\n]*\@[^>\n]*>)(?:(?!From:[^\S\n]*[^<\n]+<[^>\n]*\@[^>\n]*>).)*
于 2012-05-02T23:12:38.503 回答