Page 1 of 1

[SOLVED] Wits end with regex

Posted: Fri Feb 18, 2005 4:06 pm
by pickle
Hi folks,

I'm trying to work with regular expressions, and it's taking me way longer than I think it should.

I'm working in a custom CMS where I need to pull out all email addresses. For this case, I don't need to worry about proper format (RFC-wise), I can safely assume all email addresses are going to be of the format: username@mydomain.ca.

The problem I'm having is my setup (it may not be my expression) only catches the first email address in the string, it doesn't match to the rest of them.

So far, my setup is basically:
[edit: the regex got screwed up when a forum plugin went haywire]

Code: Select all

$pattern = "(ї^@]*@ї^\.]*\.ї\.a-z0-9]*ї\.a-z]{2,4})";
$page_contents = 'me@server.com, you@server.com';

eregi($pattern,$page_contents,$matches);

echo "<pre>";
print_r($matches);
echo "</pre>";
The result is:

Code: Select all

Array
(
    [0] => me@server.com
    [1] => me@server.com
)
Any idea why all the addresses aren't being caught?

Posted: Fri Feb 18, 2005 4:08 pm
by feyd
hint: preg_match_all() ;)

Posted: Fri Feb 18, 2005 4:22 pm
by pickle
I kind of figured you'd be the one to answer my regex question. It works like a charm - thanks!

Posted: Sat Feb 19, 2005 12:03 am
by n00b Saibot
feyd has MASTERS Degree in regexs :lol: