using re module to find " but not " alone ... is this a BUG in re?

anton antonxx at gmx.de
Thu Jun 12 11:11:07 CEST 2008


Hi,

I want to replace all occourences of " by \" in a string.

But I want to leave all occourences of \" as they are.

The following should happen:

  this I want " while I dont want this \" 

should be transformed to:

  this I want \" while I dont want this \" 

and NOT:

  this I want \" while I dont want this \\" 

I tried even the (?<=...) construction but here I get an unbalanced paranthesis
error.

It seems tha re is not able to do the job due to parsing/compiling problems 
for this sort of strings.


Have you any idea??

  Anton


Example: --------------------

import re

re.findall("[^\\]\"","this I want \" while I dont want this \\\" ")

Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
  File "C:\Python25\lib\re.py", line 175, in findall
    return _compile(pattern, flags).findall(string)
  File "C:\Python25\lib\re.py", line 241, in _compile
    raise error, v # invalid expression
error: unexpected end of regular expression




More information about the Python-list mailing list