Web Hosting Talk







View Full Version : [PHP] regex question !!!


hookgr
12-23-2004, 07:53 PM
hello,

i need a regex and cant find a solution...

could you please help me ???

i need this:

i have a data stream saved in a string, and would like to collect all valid email addresses in a table...

so i did that:

preg_match_all("regex_hoes_here", $reply, $matches);
$emails = array_unique($matches[1]);

the question is what i should use in the place of "regex_goes_here" so that it would find this:

(all emails are in this format)

texttexttext...text...mailto:X@X.X">...texttext...text

so i need the X@X.X

i thought it would be helpfull to scan for:

o:*@*.*">

and use o: as starting tag, and "> as ending...

and just collect what is inside these... (the *@*.*)

can u plz tell me how i could do this?

thanx for ur time !!!

Daniel_C
12-23-2004, 08:18 PM
well the regular expression you want is something like:

o:(.*@.*\..*)">

in php you can use the preg match all or something like that command to match all into an array.

Xenatino
12-23-2004, 08:30 PM
preg_match_all("/([0-9A-Za-z\._-])@([0-9A-Za-z\._-])\.([a-z\.])/", $reply, $matches);


Just wrote that off the top of my head, not been tested or anything so just give it a whirl!

assistanz247
12-23-2004, 10:00 PM
Hi,

preg_match_all("/([a-zA-Z0-9._-])+@([a-zA-Z0-9-])+\\.[a-zA-Z]([a-zA-Z.])*[a-zA-Z]/",$reply,$matches);

This would validate the email address more exactly, I believe.

hookgr
12-24-2004, 08:06 AM
Unfortunately, none of them did worked and returned what i need..

just to mention it again, it must find: o:xxx@xxx.xxx">
and send to table only the: xxx@xxx.xxx
(xxx = anything - all ascii symbols accepted)

WO-Jacob
12-26-2004, 09:01 PM
'^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z_.-])*@(([0-9a-zA-Z])+([-\w]*[0-9a-zA-Z])*\.)+[a-zA-Z]{2,9})$'

is what I use