Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-23-2006, 12:48 AM   PM User | #1
jskaar
New Coder

 
Join Date: Jan 2006
Location: Oslo, Norway
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
jskaar is an unknown quantity at this point
Get regex matches

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?
PHP Code:
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!
__________________
Drømmejenta: Kristen jente som progger Python!

Last edited by jskaar; 06-23-2006 at 01:20 AM..
jskaar is offline   Reply With Quote
Old 06-23-2006, 08:00 AM   PM User | #2
Mwnciau
Regular Coder

 
Join Date: May 2006
Location: Wales
Posts: 820
Thanks: 1
Thanked 82 Times in 79 Posts
Mwnciau is on a distinguished road
/(([_A-Za-z0-9-]+)(\\.[_A-Za-z0-9-]+)*@([A-Za-z0-9-]+)(\\.[A-Za-z0-9-]+)*)/iex
Mwnciau is offline   Reply With Quote
Old 06-23-2006, 09:58 AM   PM User | #3
jskaar
New Coder

 
Join Date: Jan 2006
Location: Oslo, Norway
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
jskaar is an unknown quantity at this point
Thanks for replying! In danger of beeing stupid: What does the e and x stands for?
__________________
Drømmejenta: Kristen jente som progger Python!
jskaar is offline   Reply With Quote
Old 06-23-2006, 05:27 PM   PM User | #4
Mwnciau
Regular Coder

 
Join Date: May 2006
Location: Wales
Posts: 820
Thanks: 1
Thanked 82 Times in 79 Posts
Mwnciau is on a distinguished road
well i and e stand for across lines and case insensitive but dont know about the other one (not my regex)
Mwnciau is offline   Reply With Quote
Old 06-23-2006, 06:58 PM   PM User | #5
fci
Senior Coder

 
Join Date: Aug 2004
Location: Twin Cities
Posts: 1,345
Thanks: 0
Thanked 0 Times in 0 Posts
fci is an unknown quantity at this point
refer to
http://us2.php.net/manual/en/referen....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.
fci is offline   Reply With Quote
Old 06-24-2006, 01:31 PM   PM User | #6
jskaar
New Coder

 
Join Date: Jan 2006
Location: Oslo, Norway
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
jskaar is an unknown quantity at this point
Thank you! I'm starting to figure out this regex thing now... Baby steps, of course, but very useful to learn!
__________________
Drømmejenta: Kristen jente som progger Python!
jskaar is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:16 PM.


Advertisement
Log in to turn off these ads.