Reputation: 11
I have this regular expression -
(?P<Title>.+)(?P<ReleaseYear>([0-9]+))|(?P<Title>.+)(?P<Prginfo>-[0-9])|(?P<Title>.+)(?P<Prginfo>\s+\d+\s+сезон\s*)|(?P<Title>.+)(?P<Prginfo>\s+сезон\s*\d+)|(?P<Title>.+)
This works perfectly fine in .NET code. But when I try to use it in python I am getting error - "sre_constants.error: redefinition of group name 'Title' as group 3; was group 1"
Upvotes: 1
Views: 733
Reputation: 107317
You can not use duplicate group names in python regex because it may be cause a confusion actually python use them as a dictionary keys.
(?P<name>...)
Similar to regular parentheses, but the substring matched by the group is accessible via the symbolic group name name. Group names must be valid Python identifiers, and each group name must be defined only once within a regular expression. A symbolic group is also a numbered group, just as if the group were not named.
Upvotes: 2