Re: Regular expression confusion

2006-09-24 Thread Fredrik Lundh
York wrote: > I have two backslash - a. and I want to replace them with one backslash, > but I failed: > > >>> import re > >>> a = '' > >>> re.sub(r'', '\\', '') John has already sorted the RE-specific part of the problem, but it's also worth noting that using the RE engine for

Re: Regular expression confusion

2006-09-24 Thread John Machin
York wrote: > Oh, that's right, the second arg is escaped by re compiler too. No, that's wrong, you [should] do the escaping, the compiler unescapes :-) Cheers, John -- http://mail.python.org/mailman/listinfo/python-list

Re: Regular expression confusion

2006-09-23 Thread York
Oh, that's right, the second arg is escaped by re compiler too. Thank you, John. York John Machin wrote: > York wrote: > >>I have two backslash - a. and I want to replace them with one backslash, >>but I failed: >> >> >>> import re >> >>> a = '' >> >>> re.sub(r'', '\\', '') >>Trac

Re: Regular expression confusion

2006-09-23 Thread John Machin
York wrote: > I have two backslash - a. and I want to replace them with one backslash, > but I failed: > > >>> import re > >>> a = '' > >>> re.sub(r'', '\\', '') > Traceback (most recent call last): >File "", line 1, in ? >File "/usr/lib/python2.3/sre.py", line 143, in sub >

Regular expression confusion

2006-09-23 Thread York
I have two backslash - a. and I want to replace them with one backslash, but I failed: >>> import re >>> a = '' >>> re.sub(r'', '\\', '') Traceback (most recent call last): File "", line 1, in ? File "/usr/lib/python2.3/sre.py", line 143, in sub return _compile(pattern,