[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Omaha.pm] [olug] String parsing question



Adam Haeder wrote:
What's the best (fastest) way to get from this string:

User 1 <user1@a.com>, User 2 <user2@a.com>, User 3 <user3@a.com>

to this:

user1@a.com user2@a.com user3@a.com

Consider that there could be x number of addresses on the line, so I can't
always assume 3.

On Oct 7, 2005, at 12:13 PM, Sam Tetherow wrote:
Since Jay hasn't replied yet I'll give a perl version ;)

Quick and dirty, no data validation:

#!/usr/bin/perl

while(<STDIN>) {
 $_=~s/[^<]*<([^>]*)>/$1 /g;
 print;
}

-laugh- I'm /(in)?famous/! I stole Sam's regex and made it available via command line:

$ perl -pe 's/[^<]*<([^>]*)>/$1 /g' inputfile.txt

or

$ cat inputfile.txt | perl -pe 's/[^<]*<([^>]*)>/$1 /g'

The hardcore version of this might be via Text::Balanced.

j
Omaha Perl Mongers: http://omaha.pm.org