Following is a simple piece of code about regex match:
import re
pattern = ".*"
s = "ab"
print(re.search(pattern, s))
output:
<_sre.SRE_Match object; span=(0, 2), match='ab'>
My confusion is "."
matches any single character, so here it's able to match "a"
or "b"
, then with a "*"
behind it, this combo should be able to match ""
"a"
or "aa"
or "aaa..."
or "b"
or "bb"
or "bbb..."
or other single characters that repeat for several times.
But how comes it(".*"
) matches "ab" the same time?