So I have this regex:
(^(\s+)?(?P<NAME>(\w)(\d{7}))((01f\.foo)|(\.bar|\.goo\.moo\.roo))$|(^(\s+)?(?P<NAME2>R1_\d{6}_\d{6}_)((01f\.foo)|(\.bar|\.goo\.moo\.roo))$))
Now if I try and do a match against this:
B048661501f.foo
I get this error:
File 'C:\Python25\lib\re.py', line 188, in compile return _compile(pattern, flags) File 'C:\Python25\lib\re.py', line 241, in _compile raise error, v # invalid expression sre_constants.error: redefinition of group name 'NAME' as group 9; was group 3
If I can’t define the same group twice in the same regex expression for two different cases, what do I do?
No, you can’t have two groups of the same name, this would somehow defy the purpose, wouldn’t it?
What you probably really want is this:
I refactored your regex as far as possible. I made the following assumptions:
You want to (correct me if I’m wrong):
'R1_', and two times (6 digits +'_')'01f.foo'or'.'and ('bar'or'goo'or'moo'or'roo')You could also have meant:
Which is:
'R1_', and two times (6 digits +'_')'foo','bar','goo','moo'or'roo'