regular expression
| From: | Corin Langosch | Date: | Tue, 14 Jan 2003 09:49:51 +0000 |
| Subject: | regular expression | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-131528@lists.php.net to get a copy of this message | ||
hi,
i wrote a regular expression to match email adresses:
$text = preg_replace("/([a-z0-9_]|\\-|\\.)+@([^[:space:]<>]*)([[:alnum:]-])/i",
"<a href=\"mailto:\\1\">\\1</a>",
$text);
unluckily also things like ftp://test@test.de were matched.
so i rewrote it to:
$text = preg_replace("/(?<!http:\/\/|ftp:\/\/)(([a-z0-9_]|\\-|\\.)+@([^[:space:]<>]*)([[:alnum:]-]))/i",
"<a href=\"mailto:\\1\">\\1</a>",
$text);
but this gives me:
http://gucki@test.aaa.a -> http://gucki@test.aaa.a
ftp://gucki@test.aaa.a -> ftp://gucki@test.aaa.a
gucki@test.aaa.a -> gucki@test.aaa.a
thanks for your help! :)