正则_用花括号匹配特定次数
2018-08-20 本文已影响0人
测试媛617
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