Skip to content

groupdict() returns only first character of the match if there is a single named capture group #25

@simonw

Description

@simonw

This line:

[m.groupdict() for m in rure.compile('(?P<word>\w+)').finditer("hello there")]

Returns this:

[{'word': 'h'}, {'word': 't'}]

I would expect it to return this:

[{'word': 'hello'}, {'word': 'there'}]

Adding a second named group fixes this issue for some reason:

[m.groupdict() for m in rure.compile('(?P<name>\w+)(?P<nomatch>)').finditer("hello there")]

Returns:

[{'name': 'hello', 'nomatch': ''}, {'name': 'there', 'nomatch': ''}]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions