Title: Message
Another thought, instead of trying to get what's right, why not exclude those that you don't want, such as
 
    $_='[EMAIL PROTECTED]_ [EMAIL PROTECTED]  [EMAIL PROTECTED]';
    @mails=/[^\s+;\+,\-_]+/g;
    print $mails[0]
 
By excluding all the unwanted delimiters such as \s, ;, +, -, ... you get all you want into an array then you can simple extract the first element from the array ...
 
~Mike L.
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Guthrie, Michael (GXS)
Sent: Wednesday, October 02, 2002 6:55 AM
To: 'Vitaly Sinitsin'
Cc: [EMAIL PROTECTED]
Subject: RE: regular expression question

You really need a pattern that covers all possible variation of an email address.   I don't know what exactly that is.  So I would use the code below but add a check for multiple '@' in the string.  If you get a number greater than 1 then you can use the code as is if not you would modify it to grab the whole string.  Probably should have done this first as it is the most efficient means to determine if all of the extra regex code is needed.
 
 
$str = '[EMAIL PROTECTED];[EMAIL PROTECTED]';
@e_count = split /@/, $str;
 
if (@e_count < 2) {# Only one address
    $email = $str;
}else { # Grab first of many

    if($str =~ /^([^\@]+\@[^\;\,\s\-\_]+)/) {

        $email = $1;

    }else {

        die "\nUnable to parse email address from $str\n";

    }

}

Regards,
Mike

-----Original Message-----
From: Vitaly Sinitsin [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, October 02, 2002 10:23 AM
To: Guthrie, Michael (GXS)
Subject: RE: regular expression question

ok, and if I don't know the number of emails? but I sure that ONE email at least exists?

 -----Original Message-----
From: Guthrie, Michael (GXS) [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, October 02, 2002 3:09 PM
To: 'Vitaly Sinitsin'
Cc: [EMAIL PROTECTED]
Subject: RE: regular expression question

Good point.  You would have to use the @ as it can only appear once in each address.  I would use following expression to handle this.

 

$str = '[EMAIL PROTECTED];[EMAIL PROTECTED]';

if($str =~ /^([^\@]+\@[^\;\,\s\-\_]+)/) {

$email = $1;

}

 

Regards,
Mike

-----Original Message-----
From: Vitaly Sinitsin [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, October 02, 2002 9:59 AM
To: Guthrie, Michael (GXS)
Cc: [EMAIL PROTECTED]
Subject: RE: regular expression question

nice point,
but what if email address includes '-' or '_' , meaning one of separators?
-----Original Message-----
From: Guthrie, Michael (GXS) [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, October 02, 2002 2:52 PM
To: 'Vitaly Sinitsin'
Cc: '[EMAIL PROTECTED]'
Subject: RE: regular expression question

If you have a definitive list of delimiters as it appears you do, then grab all characters that are not in that list from the beginning of the string.  I haven't tried this but it should work.

<--
$str = '[EMAIL PROTECTED];[EMAIL PROTECTED]';
if($str =~ /^([^\;\,\s\-\_]+)/) {
        $email = $1;
}


Regards,
Mike


-----Original Message-----
From: Vitaly Sinitsin [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, October 02, 2002 9:42 AM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: RE: regular expression question


forget to mention: ';'  isn't a delimiter, the idea is to get the first
email only! even if there are more. And emails can be separated by the
following signs only:
';' ',' '(' ')' 'white space' '-' '_'

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of
[EMAIL PROTECTED]
Sent: Wednesday, October 02, 2002 2:32 PM
To: Vitaly Sinitsin; [EMAIL PROTECTED]
Subject: RE: regular expression question


Hi,

This script works

<--
for ('"[EMAIL PROTECTED];[EMAIL PROTECTED]')
{
  /^(.*);(.*)$/;
  print $1 . "\n";
}
-->

Another way could be
<--
@array = split /;/, '"[EMAIL PROTECTED];[EMAIL PROTECTED]';
print $array[0];
-->

And so many other...

Olivier Gerault
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to