Let’s say if I have a string like this
a_string = '.aa.bb.cc.dd'
I want to match all substrings that start with .
and end with dd
, the pattern and results would be like
pattern = r'..*dd'
results = ['.aa.bb.cc.dd', '.bb.cc.dd', '.cc.dd', '.dd']
However, if I use re.findall like
matches = re.findall(r'..*dd', a_string)
It would only output
['.aa.bb.cc.dd']
That makes me puzzled, why doesn’t re matches all of the substrings that satisfy the pattern
New contributor
Shengming Zhao is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.