Ezio Melotti added the comment:
The space you see is the character \x00:
>>> re.sub('a+', r'__\0__', 'bbaaabb')
'bb__\x00__bb'
The re documentation says:
"""
\number
Matches the contents of the group of the same number. Groups are numbered
starting from 1.
"""
so the re module is behaving as documented (i.e. \0 can't be used to indicate
the whole match).
I agree that this is somewhat inconsistent with the behavior of .group(0) and
with other languages, however adding support for \0 would probably be backward
incompatible, and as you already mentioned in your message there's a simple
workaround that can be used instead.
Matthew, does regex.py support \0?
Do you know if there's a reason why this is not supported?
----------
components: +Regular Expressions
nosy: +ezio.melotti, mrabarnett
versions: -Python 3.1, Python 3.5
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue17426>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com