Hello Steven,

I am perhaps a poor tradesman but I have to blame my thunderbird tool :-P .
Because expression = *' "" '*  is in fact fact expression = ' "" '.
The bold appear as stars I don't know why. I need to have escapes for passing it to another language (TCL interpreter).
So I will rewrite it not _in bold_:

$ python
Python 2.7.1rc1 (r271rc1:86455, Nov 16 2010, 21:53:40)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> expression = ' "" '

>>> re.subn(r'([^\\])?"', r'\1\\"', expression)

But if I remove '?' I get the following:

>>> re.subn(r'([^\\])"', r'\1\\"', expression)
(' \\"" ', 1)

   * On linux using my good old sed command, it is working with my '?'
     (0-1 match):

$ echo ' "" ' | sed 's/\([^\\]\)\?"/\1\\"/g'*
* \"\"

For me linux/unix sed utility is trusty and is the reference.

Regards
Karim


On 02/03/2011 11:43 AM, Steven D'Aprano wrote:
Karim wrote:

Hello,

I am trying to subsitute a '""' pattern in '\"\"' namely escape 2 consecutives double quotes:

You don't have to escape quotes. Just use the other sort of quote:

>>> print '""'
""


   * *In Python interpreter:*

$ python
Python 2.7.1rc1 (r271rc1:86455, Nov 16 2010, 21:53:40)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> expression = *' "" '*

No, I'm sorry, that's incorrect -- that gives a syntax error in every version of Python I know of, including version 2.7:

>>> expression = *' "" '*
  File "<stdin>", line 1
    expression = *' "" '*
                 ^
SyntaxError: invalid syntax


So what are you really running?



>>> re.subn(*r'([^\\])?"', r'\1\\"', expression*)

Likewise here. *r'...' is a syntax error, as is expression*)

I don't understand what you are running or why you are getting the results you are.


> *Indeed what's the matter with RE module!?*

There are asterisks all over your post! Where are they coming from?

What makes you think the problem is with the RE module?

We have a saying in English:

"The poor tradesman blames his tools."

Don't you think it's more likely that the problem is that you are using the module wrongly?

I don't understand what you are trying to do, so I can't tell you how to do it. Can you give an example of what you want to start with, and what you want to end up with? NOT Python code, just literal text, like you would type into a letter.

E.g. ABC means literally A followed by B followed by C.
\" means literally backslash followed by double-quote





_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to