python – Regex pattern confusion

I am learning regex using Python and am a little confused by this tutorial I am following. Here is the example:

rand_str_2 = "doctor doctors doctor's"

# Match doctor doctors or doctor's
regex = re.compile("[doctor]+['s]*")
matches = re.findall(regex, rand_str_2)
print("Matches :", len(matches))

I get 3 matches

When I do the same thing but replace the * with a ? I still get three matches

regex = re.compile("[doctor]+['s]?")

When I look into the documentation I see that the * finds 0 or more and ? finds 0 or 1

My understanding of this is that it would not return “3 matches” because it is only looking for 0 or 1.

Can someone offer a better understanding of what I should expect out of these two Quanti­fiers?

Thank you

Read more here: Source link