import re

pattern = '^M?M?M?$'

print(re.search(pattern, 'M'))
print(re.search(pattern, 'MM'))
print(re.search(pattern, 'MMM'))
print(re.search(pattern, 'MMMM'))
print(re.search(pattern, ''))

"""
/usr/local/bin/python3 /Users/moqi/Documents/Code/dive-into-python3-practice/c06/p164_check_thousands.py
<re.Match object; span=(0, 1), match='M'>
<re.Match object; span=(0, 2), match='MM'>
<re.Match object; span=(0, 3), match='MMM'>
None
<re.Match object; span=(0, 0), match=''>

Process finished with exit code 0
"""
