I have the following code using multiple capturing groups within a non-capturing group:
>>> regex = r'(?:a ([ac]+)|b ([bd]+))'
>>> re.match(regex, 'a caca').groups()
('caca', None)
>>> re.match(regex, 'b bdbd').groups()
(None, 'bdbd')
How can I change the code so it outputs either ('caca') or ('bdbd')?
('caca',)and('bdbd',)r'(?|a ([ac]+)|b ([bd]+))'rewhen it comes to sophisticated pattern matching or handling large texts that it must be part of the default installation bundle in my opinion.