[ILUG] split strings using re

From: Padraig Brady (padraig.brady at domain corvil.com)
Date: Wed 11 Sep 2002 - 13:07:00 IST


OK say I have lines of the form:

field1 "field2" "field 3"
"field1" field2 "field 3"
field1 "field2" field3

you get the idea...

How do I read each field into an array?
(while removing any quotes at the same time
would be a bonus).

A python answer would be perfect,
but I can convert the equivalent
a perl solution very easily I guess.

What I have in python now is:
fields = re.split('[ ]+|"([^"]*)"', record)
And this is OK except there are empty and
null fields returned. I'm sure there is
a more elegant re to acheive this?

cheers,
Padraig.



This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:18:48 GMT