At 10:49 14-1-03, you wrote:
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:[EMAIL PROTECTED] 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:[EMAIL PROTECTED] -> http:[EMAIL PROTECTED]
ftp:[EMAIL PROTECTED] -> ftp:[EMAIL PROTECTED]
[EMAIL PROTECTED] -> [EMAIL PROTECTED]

This seems to work:

$text =
preg_replace("/([^\/a-z0-9_])(([a-z0-9_]|\\-|\\.)+@([^[:space:]<>]*)([[:alnum:]-]))/i",
"\\1<a href=\"mailto:\\2\";>\\2</a>", $text);

I did not check the entire regexp but it seems to do what you need.
Um, the NOT thingy in a regexp is the ^ in stead of the !.

And my line will not tagify any email preceded by a forward slash.

Chris Hayes


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to