Suppose I have a regular expression (a)|(b)|(c)|(d)
. If I apply it to text 'foobar'
I get a match object
>>> compiled = re.compile('(a)|(b)|(c)|(d)')
>>> compiled.search('foobar').groups()
(None, 'b', None, None)
How do I extract the 'b'
from here? Or in general, how do I extract the first match from an unknown number of groups (can happen when the regexp was built dynamically)?