例如:
import
re
pattern
=
r
"egg(spam)*"
if
re.match(pattern,
"egg"
):
print
(
"匹配 1"
)
"eggspamspamegg"
("
"匹配 2"
"spam"
"匹配 3"
结果:
>>>
匹配
1
2