[SOLVED] Wits end with regex

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

[SOLVED] Wits end with regex

Post 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?
Last edited by pickle on Mon Nov 28, 2005 1:51 pm, edited 1 time in total.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

hint: preg_match_all() ;)
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

I kind of figured you'd be the one to answer my regex question. It works like a charm - thanks!
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

feyd has MASTERS Degree in regexs :lol:
Post Reply