开发者

I need a regex that return non emails from a string

After a lot of searching I found this regex that finds emails inside a string:

preg_match_all("/[a-z0-9]+([_\\开发者_StackOverflow中文版.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}/i", $text, $output);

How can I have the exact oposite effect? I really need to know what are the words that aren't a valid email address :-)


How can I have the exact oposite effect? I really need to know what are the words that aren't a valid email address :-)

If the mentioned regular expression works sufficiently for you, use preg_replace to filter out the matches, the remaining text will be everything that isn't what matched:

<?php
$text = 'Your text here.';

// replace everything that matches with ''.
$text = preg_replace( "/^[^a-z0-9]+([^_\.-][^a-z0-9]+)^@([^a-z0-9]+([^.-][^a-z0-9]+))+\.[a-z]{2,}/i", '', $text );

echo $text;


If you use preg_replace($pattern, "", $string) then you'll get back a string which has had everything that matches the given pattern removed. You could then tokenize this string (ie. call split on it) to get a list of words that don't match the pattern.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜