例如:
import re
pattern = r"gr(a|e)y"
match = re.match(pattern, "gray")
if match:
print ("Match 1")
match = re.match(pattern, "grey")
if match:
print ("Match 2")
match = re.match(pattern, "griy")
if match:
print ("Match 3")
结果:
>>> Match 1 Match 2 >>>