I wish to expand on the discussion on the following question
In a regular expression, match one thing or another, or both
with a new condition that I want to name the groups consistently. Something like this -
((?P<A>A)|(?P<B>B)) | ((?P<A>A)(?P<B>B))
which triggers re.error: redefinition of group name ...
in Python.
Additional info in case it helps: In my specific application, A is a date and B is a time. Basically I want to allow users to enter a date, or a time, or a date followed by a time (which is why A?B? would not work for me as I do not want it empty).
The group name feature of regex turns out to be very handy when it comes to parsing the date and/or time info to datetime objects and functionalities. This is why I want to be able to keep naming A A and B B even when the pattern repeats. This makes the accepted solution in the cited discussion not work for me.
Edit: Yes, I agree that repeating a pattern is not a good idea in the first place especially when date and time are already messy.