View Full Version : Get regex matches

06-23-2006, 12:48 AM
I got a text: $text = "Blah... user1@domain1.com ...blah.... user2@domain2.com ...";

How do I get hold of the e-mail addresses: user1@domain1.com, user2@domain2.com, ... using regex? How to do it with php?

Would this be an smart way to do it?

preg_match_all("/(\w|\.)*@\w*\.\w*/", $text, $match);
$match contains all matches, all e-mail addresses in $text. (I also want to match e-mail addresses like user1.sub@domain1.com.)

Thanks for any suggestions!

06-23-2006, 08:00 AM

06-23-2006, 09:58 AM
Thanks for replying! In danger of beeing stupid: What does the e and x stands for?

06-23-2006, 05:27 PM
well i and e stand for across lines and case insensitive but dont know about the other one (not my regex)

06-23-2006, 06:58 PM
refer to
i = case insensitive
e = this will do an eval if you embed php code in it
x = whitespace characters are ignored in the regex pattern

the pattern really only needs the i though.

06-24-2006, 01:31 PM
Thank you! I'm starting to figure out this regex thing now... Baby steps, of course, but very useful to learn!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum