error in module re?
Ken Koller
ken.koller at kla-tencor.com
Mon Sep 13 18:58:59 EDT 1999
I think you need to use a raw string such as r'\2-\1' or escape the slash
'\\2-\\1'
re.sub('(a+)\s(b+)', r'\2-\1', 'aaa bbb')
or
re.sub('(a+)\s(b+)', '\\2-\\1', 'aaa bbb')
"Chris..." wrote:
> Dear Pythoners...
>
> Is this an implementation or documentation error?
> >>> import re
> >>> re.sub('(a+)\s(b+)', '\2-\1', 'aaa bbb')
> '\002-\001'
> instead of
> 'bbb-aaa'
> The documentation says, that you can use backreferences in replacement
> string, but only \g<number> works.
>
> My version is:
> Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32
>
> bye
> Chris...
More information about the Python-list
mailing list