2012-05-02 4 views
1

これらの集約された電子メールの中に名前と電子メールアドレスがたくさんあり、文書全体でFirst Last <[email protected]>以外のすべてを取り除きたいと思っています。基本的に私は、私はこれだけのテキストから...正規表現は特定の単語の後に2つの名前と<電子メールアドレス>以外のものすべてに一致します

Name Wood <[email protected]> 
Name Wood <[email protected]> 

を一致させたい

From: Name Wood <[email protected]> 
Subject: Yelp entries for iPod contest 
Date: April 20, 2012 12:51:07 PM EDT 
To: [email protected] 

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 protected]> 
Subject: reviews 2 and 3 
Date: April 20, 2012 12:44:26 PM EDT 
To: [email protected] 

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... 

...持っています。だから基本的には、単語"From: "とを除いた"<"+email address+">"という単語の次の2つの単語と一致させたい。私は2つの全体の単語(何とか{0,2}を使って)を検索し、<の文字からもう1つの>までの電子メールアドレスを検索することは、否定的な先読みであると考えています。

+0

どのような正規表現の実装を使用しますか? Perl? Python? Java?他に何か? – alan

答えて

0

あなたはこれを行うことができます:

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

しかし、あなたがそれをやろうとしていることはほとんど不明である:

/(?:From:)(.*)/g 
0

この正規表現は、あなたが探しているものを見つけるでしょうあなたの質問から。一致したテキストはおそらく1つ以上のグループに入れて、必要なテキストを抽出する必要があります。 (グループ内の名前か、別のグループのメールか、または両方を一緒にするか)あなたはそれで何をしたいのか分からないので、より多くの情報を提供する必要があります。上記は最も簡単なシナリオです。

説明:

(?<=From:) # positive lookbehind to find "From:" 
\s*   # optional whitespace 
[^<]+<  # everything up to the first '<' (the name) 
[^>]+>  # everything up to the '>' (the email) 
+0

OKこれは完璧です。今はその選択肢で何か他のことをやりたいのですが、これを逆にしてこの選択以外のすべてを選択する方法はありますか? – mochabcha

+0

一言で言えば、いいえ。あなたは本当に何をしようとしていますか?名前と電子メールアドレスを取り除き、他のものはすべて保管しますか?あなたの質問は、文書全体を通して「最初の最後」以外のすべてを取り除いたと言っています_。今あなたは違ったことを言っている。 – alan

+0

ちょうど、私はこの正規表現を適用し、 "delete"をヒットし、人々の名前と住所だけを残したいと思います。そうでない場合は、テキスト領域でこれを受け入れ、正規表現の結果を別の領域に出力するフォームを作成できます。 – mochabcha

0

すべてが、名前と電子メールを削除したい場合。
修飾子「S」(ドットが改行を含んで)、両方の正規表現のための
グローバル検索と置き換えこれは高速ですが、sucessesに余分な改行を残すだろう$1\n

です。

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

これは遅いです(先読みを使用します)が、余分な改行を残すことはありません。

Find .*?From:[^\S\n]*([^<\n]+<[^>\n]*\@[^>\n]*>)(?:(?!From:[^\S\n]*[^<\n]+<[^>\n]*\@[^>\n]*>).)* 
関連する問題