例如:
import re pattern = r"9{1,3}$" if re.match(pattern, "9"): print("Match 1") if re.match(pattern, "999"): print("Match 2") if re.match(pattern, "9999"): print("Match 3")
结果:
>>> Match 1 Match 2 >>>
1