import re
haRex = re.compile(r'(ha){3}')
mo1 = haRex.search('hahaha')
print(mo1.group())
laRex = re.compile(r'(ha){2,3}')
mo2 = laRex.search('haha')
print(mo2.group())
结果是:
hahaha
haha
import re
haRex = re.compile(r'(ha){3}')
mo1 = haRex.search('hahaha')
print(mo1.group())
laRex = re.compile(r'(ha){2,3}')
mo2 = laRex.search('haha')
print(mo2.group())
结果是:
hahaha
haha
本文标题:正则_用花括号匹配特定次数
本文链接:https://www.haomeiwen.com/subject/wyoliftx.html
网友评论