PDA

View Full Version : Get regex matches



jskaar
06-23-2006, 01: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?

UPDATE:
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!

Mwnciau
06-23-2006, 09:00 AM
/(([_A-Za-z0-9-]+)(\\.[_A-Za-z0-9-]+)*@([A-Za-z0-9-]+)(\\.[A-Za-z0-9-]+)*)/iex

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

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

fci
06-23-2006, 07:58 PM
refer to
http://us2.php.net/manual/en/reference.pcre.pattern.modifiers.php
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.

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