php - Regex to parse Email Form "To" field -


if there 1 handle this, correct regex pattern extract email addresses string coming email form "to" line, allows addresses delimited commas ",", semicolons ";", spaces, or combination of three. regex has able ignore "noise" text, such if address enclosed in "<" , ">" characters, or has actual name next email address. example, string in field:

"joe smith" <jsmith@example.com>, kjones@aol.com; someoneelse@nowhere.com mjane@gmail.com 

the pattern should able return following matches of: jsmith@example, kjones@aol.com, someoneelse@nowhere.com, mjane@gmail.com

i using php, if can't done in single regex im open other php-based solutions.

thanks

try

\b[a-z0-9._%+-]+@(?:[a-z0-9-]+\.)+[a-z]{2,6}\b 

(courtesy of regexbuddy) in

preg_match_all('/\b[a-z0-9._%+-]+@(?:[a-z0-9-]+\.)+[a-z]{2,6}\b/i', $subject, $result, preg_pattern_order); $result = $result[0]; 

note /i modifier make case-insensitive.

see this question explanation of drawbacks of regexes finding e-mail addresses in string.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -