No, you cannot have two groups with the same name, this somehow would not justify the goal, would you?
What you probably really want is:
^\s*(?P<NAME>\w\d{7}|R1_(?:\d{6}_){2})(01f\.foo|\.(?:bar|goo|moo|roo))$
I reorganized your regex as far as possible. I made the following assumptions:
You want (correct me if I am wrong):
- ignore space at the beginning of a line
- matches any of the following elements in a group named "NAME":
- a letter followed by 7 digits, or
"R1_" and two times (6 digits + "_" )
- followed by:
"01f.foo" or"." and ( "bar" or "goo" or "moo" or "roo" )
- followed by the end of the line
You could also keep in mind:
^\s*(?P<NAME>\w\d{7}01f|R1_(?:\d{6}_){2})\.(?:foo|bar|goo|moo|roo)$
What is:
- ignore space at the beginning of a line
- matches any of the following elements in a group named "NAME":
- letter followed by 7 digits and "01f"
"R1_" and two times (6 digits + "_" )
- point
"foo" , "bar" , "goo" , "moo" or "roo"- end of line
source share