例如:
import re pattern = r"pam" match = re.search(pattern, "eggspamsausage") if match: print(match.group()) print(match.start()) print(match.end()) print(match.span())
结果:
>>> pam 4 7 (4, 7) >>>
1