Reading plain text file database tables

Stephan Houben stephan at pcrm.win.tue.nl
Thu Sep 9 08:24:41 EDT 1999


On Thu, 09 Sep 1999 17:45:28 +0800, Li Dongfeng 
<mavip5 at inet.polyu.edu.hk> wrote:

>Thanks for the direction. I'm also
>trying to solve this with RE. But in order
>to extract "ab \" cd" like structure,
>your [^"\\] seems puzzling, because anything
>inside [] represent only one character, not
>the '\"' two character sequence. 

No, but the other possibility handles that case.

[^"\\"] means "match anything NOT a " or a \".
\\. means "match a \ followed by anything (especially \")".

Together these mean: match anything not containing a
", except when " is preceded by \.

There are other ways to express this idea; another one
that is pretty clear (I hope) is:

([^"]*\\")*[^"]*

This interprets the string as:

<portion containing no "> + \" + <portion containing no ">
+ \" + ... + \" + <portion containing no ">

Aren't regexes fun?

Greetings,

Stephan




More information about the Python-list mailing list