开发者

PHP - How to identify e-mail addresses from input containing lines of misc data

Apologizing in advance for yet another email pattern matching query. Here is what I have so far:

$text = strtolower($intext);
$lines = preg_split("/[\s]*[\n][\s]*/", $text);
$pattern = '/[A-Za-z0-9_-]+@[A-Za-z0-9_-]+\.([A-Za-z0-9_-][A-Za-z0-9_]+)/';
$pattern1= '/^[^@]+@[a-zA-Z0-9._-]+\.[a-zA-Z]开发者_运维问答+$/';
foreach ($lines as $email) {
preg_match($pattern,$email,$goodies);
$goodies[0]=filter_var($goodies[0], FILTER_SANITIZE_EMAIL);
if(filter_var($goodies[0], FILTER_VALIDATE_EMAIL)){
array_push($good,$goodies[0]);
}
}

$Pattern works fine but .rr.com addresses (and more issues I am sure) are stripped of .com

$pattern1 only grabs emails that are on a line by themselves.

I am pasting in a whole page of miscellaneous text into a textarea that contains some emails from an old data file I am trying to recover.

Everything works great except for the emails with more than one "." either before or after the "@".

I am sure there must be more issues as well.

I have tried several patterns I have found as well as some i tried to write.

Can someone show me the light here before I pull my remaining hair out?


How about this?

/((?:\w+[.]*)*(?:\+[^@ \t]*)?@(?:\w+[.])+\w+)/

Explanation: (?:\w+[.])* recognizes 0 or more instances of strings of word characters (alphanumeric + _) optionally separated by strings of periods. Next, (?:\+[^@ \t]*)? recognizes a plus sign followed by zero or more non-whitespace, non-at-sign characters. Then we have the @ sign, and finally (?:\w+[.])+\w+, which matches a sequence of word character strings separated by periods and ending in a word character string. (ie, [subdomain.]domain.topleveldomain)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜