Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

preg match

Status
Not open for further replies.

peacecodotnet

Programmer
May 17, 2004
123
US
i'm looking for a preg_match_all pattern that would return a nice array of all email addresses in a string

thanks!

Peace out,
Peace Co.
 
>> all email addresses

where do u get the email addressess from?

Known is handfull, Unknown is worldfull
 
I'll give you an example. Let's say the string was

"my email address is kid@rock.com and his email address is you@fool.com."

What I want it to do is do something like this:

preg_match_all("SOMEPATTERN", $string, $return);

and then $return will be some array, that has something like

kid@rock.com
you@fool.com

you see?


Peace out,
Peace Co.
 
First, read a tutorial on regular expressions. Then try something like:
Code:
\b[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}\b
which, interestingly enough, I found in the first screen of the first hit return by a google search for 'regular expression tutorial'
 
try:
\b\w+@(\w+\.)+[\w]+\b

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top