Regular expression confusion
York
yorklee70 at gmail.com
Sat Sep 23 21:28:20 EDT 2006
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 "<stdin>", line 1, in ?
File "/usr/lib/python2.3/sre.py", line 143, in sub
return _compile(pattern, 0).sub(repl, string, count)
File "/usr/lib/python2.3/sre.py", line 258, in _subx
template = _compile_repl(template, pattern)
File "/usr/lib/python2.3/sre.py", line 245, in _compile_repl
raise error, v # invalid expression
sre_constants.error: bogus escape (end of line)
>>>
anybody knows why?
Thanks,
York
More information about the Python-list
mailing list