Skip to content

Making a capture group inside a non capturing group causes the non-capturing group to capture. #132556

Closed as not planned
@AdrienDerobert

Description

@AdrienDerobert

Bug report

Bug description:

For some reason declaring a capture group inside a non-capturing group causes the non-capturing group to capture its content. Either the documentation doesn't explain the non-capturing group behavior correctly or this is a bug.

Note: The example here doesn't need the non-capturing group but I use it in a longer > regex. This is the minimal setup for reproducing the behavior I'm encountering.

import re
match = re.match(r'(:?test[(]([^)]*)[)])', "test(abc)")
print(match)

Result:

('test(abc)', 'abc')

Expected result:

('abc')

CPython versions tested on:

3.13, 3.12

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions