Re: regular expression
| From: | Chris Hayes | Date: | Tue, 14 Jan 2003 10:55:28 +0000 |
| Subject: | Re: regular expression | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-131532@lists.php.net to get a copy of this message | ||
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://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.aThis 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