Search code examples
pythonpython-re

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."?


Solution

  • 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.