Re: [ILUG] split strings using re

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


Waider wrote:
> Padraig Brady wrote:
> |
> | 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?
> |
>
> Here's the canonical Perl solution:
> http://www.perldoc.com/perl5.6/faq/perlfaq4.html#How-can-I-split-a-%5bcharacter%5d-delimited-string-except-when-inside%0a%5bcharacter%5d--(Comma-separated-files)

Ouch, kinda scary. python has (?:) support also.

> Personally, when faced with this sort of task, I just break it down
> rather than trying to accomplish it in a single clever step. Usually I
> get the code written faster.

Probably better.

Padraig.



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