[olug] String parsing question

Sam Tetherow tetherow at shwisp.net
Sat Oct 15 17:29:35 UTC 2005


Jay Hannah wrote:

> 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
>
>
> _______________________________________________
> OLUG mailing list
> OLUG at olug.org
> http://lists.olug.org/mailman/listinfo/olug
>
> !DSPAM:4351366289236473718276!
>
>
Yeah, but it took you a week to do it :)

    Sam Tetherow
    Sandhills Wireless



More information about the OLUG mailing list