Reading plain text file database tables

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


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

>
>
>Stephan Houben wrote:
>> 
>> A regular expression that matches strings within "..",
>> while escaping " with \, is:
>> 
>> r = re.compile(r'"([^"\\]|(\\.))*"')
>> 
>
>r=re.compile(r'".*[^\\]?"')
>worked, e.g.
>print r.match('"abc\\"ef"')
>"abc\"ef"
>The idea is, if the ending '"' is behind
>a '\' then it's not an ending '"'.

Unfortunately, this also matches the complete string
in case of '"abc"ef"'. It also matches '"abd\\"'.
Basically, the regex .*[^\\]? is equivalent to the regex .* .
In general, the regex .*<something>? will always be equivalent
to .*, because both match ANY string.

Greetings,

Stephan





More information about the Python-list mailing list