Is there a way to use same name in regex named group in python?
e.g.(?P<n>foo)|(?P<n>bar)
.
Use case:
I am trying to capture type
and id
with this regex:
/(?=videos)((?P<type>videos)/(?P<id>d+))|(?P<type>w+)/?(?P<v>v)?/?(?P<id>d+)?
from this strings:
- /channel/v/123
- /ch/v/41500082
- /channel
- /videos/41500082
For now I am getting error:
redefinition of group name 'id' as group 6; was group 3
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…