LA.pm: Regex

Samy Kamkar [CommPort5] CommPort5 at LucidX.com
Fri Jul 20 20:02:00 CDT 2001


$example = 'Port, Comm <cp5 at lucidx.com>';

($last, $first, $email) = $example =~
/^([^,]+),\s+([^\s]+)\s+<([^>]+)>$/;
print "$first $last - $email\n";

that prints:
Comm Port - cp5 at lucidx.com

Arkadiy Sudarikov wrote:
> 
> Dear all,
> 
> If I need to get name and email, then what's the regex?
> 
> I have 'Last name, First name <email at server.com>'.
> 
> I need 'Last name, First name', 'email at server.com'.
> 
> I use this,
> 
> if ($sender=~ m/^(.+)\s*\<(.+\@.+)\>$/) {
>  print p $1;
>  print p $2 }
> 
> But there is problem with space between name and email, between '... name
> <...'.
> 
> Suggestions, anyone?

-- 
Samy Kamkar -- (877) 898-1424 -- CommPort5 at LucidX.com
LucidX.com / pdump.org / LA.pm.org



More information about the Losangeles-pm mailing list