7 Dec
2019
7 Dec
'19
6:37 a.m.
Well, match objects already accept subscripting as an alternative to .group(), so:
re.search(...)[0]
The semantics are not the same as those of: re.findall(...)[0] Subscripting a Match object will yield the match for a single group, which is always a string, while the first element in the list returned by *findall()* will be a tuple if several groups matched. As others have pointed out, there is an asymmetry in the library regarding Match-return and string/tuple-return functions, and that leads to *findal(...)[0].* -- Juancarlo *Añez*