Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting emails out of string - regex syntax + preg_match_all [closed]

I'm trying to get emails out of a string:

$string = "bla bla [email protected] MIME-Version: [email protected] bla bla bla";
$matches = array();
$pattern = '\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b';
preg_match_all($pattern,$string,$matches);
print_r($matches);

The error I'm getting is :

Delimiter must not be alphanumeric or backslash

I got the regex syntax from here http://www.regular-expressions.info/email.html

like image 622
homerun Avatar asked Feb 24 '13 10:02

homerun


1 Answers

Like this

$pattern = '/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i';

Or smaller version :)

$pattern = '/[a-z\d._%+-]+@[a-z\d.-]+\.[a-z]{2,4}\b/i';
like image 60
Winston Avatar answered Oct 14 '22 05:10

Winston