Skip to content

re(regex) should take '\0' as '\g<0>' instead of '\x00' #128578

@noisnemid

Description

@noisnemid

Feature or enhancement

CURRENT STATUS

Python 3.13.1 (tags/v3.13.1:0671451, Dec  3 2024, 19:06:28) [MSC v.1942 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> p=re.compile(r'a')

p.sub(r'\0-','axa')
'\x00-x\x00-'

 p.sub(r'\g<0>-','axa')
'a-xa-'

Reasons for this

The consistency of Python code style is an important reason for its favorable reception. However, as shown in the code demonstrated just now, this is not well achieved in the re module. \1 and the like are treated as capture groups, but \0 is the only exception, which is unreasonable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions