1

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"

1
  • Just remove the group names. Commented Jul 30, 2015 at 12:53

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.