[olug] String parsing question
Jay Hannah
jay at jays.net
Sat Oct 15 16:59:15 UTC 2005
Adam Haeder wrote:
> What's the best (fastest) way to get from this string:
>
> User 1 <user1 at a.com>, User 2 <user2 at a.com>, User 3 <user3 at a.com>
>
> to this:
>
> user1 at a.com user2 at a.com user3 at 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
More information about the OLUG
mailing list