I know it's a pretty simple question. I happened to look at a regex example.
import re
pattern = r'^M?M?M?$'
s = "MDM"
re.search(pattern, s)
May I know why it doesn't match the string s
? AFAIK, ?
is to specify 0 or 1 occurence. It matches MMM though.
However the same string matches when the pattern is r'M?M?M?$'
or r'^M?M?M?'
. I am not getting what makes the difference here. Could someone please explain?