While looking into the regular expression, I found the following example:
>>> import re
>>> p = re.compile('.*[.].*$')
>>> m = p.search('foo.bar')
>>> print(m.group())
foo.bar
I don't understand the process in which it recognizes simple filename with extensions like foo.bar
, abc.xyz
, my_files.txt
. I thought this code would work like this:
.
matches with any character.*
causes to match 0 or more repetitions.- By 1. and 2., the whole string(
foo.bar
) matches with.*
. [.]
tries to find character.
, but there are no characters left..*$
doesn't do anything.- No matches found.
I wonder how this code actually works.