+ means"match one or more"
the group proceding a plus must appear at least once.
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
import re
re1=re.compile(r'bat(wo)+man')
mo1=re1.search("the adventure of batman")
#print("mo1.group():",mo1.group())
#出现错误,wo至少出现一次
mo2=re1.search("the adventure of batwoman")
print("mo2.group():",mo2.group())
mo3=re1.search("the adventure of batwowowowoman")
print("mo3.group():",mo3.group())

本文通过一个具体的正则表达式实例,展示了如何使用Python进行文本模式匹配。具体介绍了如何利用正则表达式来查找字符串中特定模式出现一次或多次的情况,并提供了多个示例加以说明。
31万+

被折叠的 条评论
为什么被折叠?



