Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the meaning of "Empty matches are included in the result."?

I am referring to the documentation of the re.findall function:

What is the meaning of "Empty matches are included in the result."?

like image 573
variable Avatar asked Mar 03 '23 08:03

variable


2 Answers

This happen when you use groups that matches empty string , example:

 print(re.findall(r'(\w)(\d?)(\w)', "bc"))

OUPUT:

[('b', '', 'c')]

Here group (\d?) matches '' and is included in the result.

like image 171
Charif DZ Avatar answered Apr 25 '23 12:04

Charif DZ


It just means when the match is “” or an empty string, that it is included in the list of results.

like image 43
David Kong Avatar answered Apr 25 '23 13:04

David Kong