Wow, you have some good problems. Only solution I was able to come up
with was something like this:
$s = '[EMAIL PROTECTED], "Blow, Joe" <[EMAIL PROTECTED]>,Joe Blow
<[EMAIL PROTECTED]>';
while($s) {
# This is to match [EMAIL PROTECTED]
if($s =~ /^([\w._]+\@[\w._]+),?\s*/) {
$s = $';
print $1,"\n";
}
# This is to match "Blow, Joe" <[EMAIL PROTECTED]>
elsif($s =~ m/^(\".+\")\s*(\<?[\w._]+\@[\w._]+\>?),?\s*/) {
$s = $';
print $1," ",$2,"\n";
}
# This is to match Joe Blow <[EMAIL PROTECTED]>
elsif($s =~ m/^(.+)\s{1,}(\<?[\w._]+\@[\w._]+\>?),?\s*/) {
$s = $';
print $1," ",$2,"\n";
}
else {
die "Could not make a match. $s is fubared\n";
}
}
I'm not even saying this is the right way to do it, in fact it's damn
ugly. I'll be the first to admit that. But, with the original test
line you gave of:
$s = '[EMAIL PROTECTED], "Blow, Joe" <[EMAIL PROTECTED]>,Joe Blow
<[EMAIL PROTECTED]>';
It works flawless. But, that doesn't mean it will work with a longer
string. Plus, you might want to replace the while loop with something a
bit better, or perhaps put something in the while to make sure $s is
changing, if not die. I did it with a quick else at the end of the
while. Otherwise you'll end up with an infinite loop on your hands if
one little thing isn't right. I sure hope somebody can come up with a
better solution, but for now this will work. :o)
Brian Johnson
Partner/Systems Administrator/Programmer
Source1Hosting.tv, LLC (www.source1hosting.tv)
Source1Results.com, LLC (www.source1results.com)
I may be insane, but remember - The only
difference between an insane man and a
genius is his jacket.
> Brian <[EMAIL PROTECTED]> wrote:
> >
> > I'm way rusty on my regexp's (been on vacation for a month
> without doing
> > any) but try this:
> >
> > $s =~ m/^([^,]+),\s*(\".+\>),(.+)/;
> >
> > $1 will be "[EMAIL PROTECTED]"
> > $2 will be '"Blow, Joe" <[EMAIL PROTECTED]>'
> > $3 will be "Joe Blow <[EMAIL PROTECTED]>"
> >
> > This will work as long as all the lines are in the format you gave
> > earlier:
> > $s = '[EMAIL PROTECTED], "Blow, Joe" <[EMAIL PROTECTED]>,Joe Blow
> > <[EMAIL PROTECTED]>';
> >
> > If not, lemme know and I'll do my best (or somebody else
> will I'm sure)
> > to come up with something a bit more forgiving. This
> regexp is really
> > ugly and mean.
> >
>
> Actually, the string is a list of one or more email addresses where
> each email address is
> (1) an optional name, which, if it contains a comma, the
> whole thing is
> quotes
> (2) and an email address, possibly inside < >
>
> Examples: Mike Miller <[EMAIL PROTECTED]>
> "Miller, Mike" <[EMAIL PROTECTED]>
> <[EMAIL PROTECTED]>
> [EMAIL PROTECTED]
>
> And the addresses in the string are separated by a comma (or
> a comma and
> whitespace).
>
> This is why I'm been unable to come up with a regex.
>
> :-)
>
> Thanks,
>
> -Mike
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]