多重匹配

多重匹配

作者:LAMP小白  点击:2128  发布日期:2013-10-22 23:26:05  返回列表

findall函数会返回与正则匹配但是不重叠的字符

finditer函数会返回一个迭代器,它将生成match实例

#!/usr/bin/python
#coding:utf8
import re
text = 'mio is mio say mio mio!'
pattern = r'mio'
for match in re.findall(pattern, text):
    print "found %s" % match
       
for match in re.finditer(pattern, text):
    s = match.start()
    e = match.end()
    print "found %s at %d:%d" % (text[s:e], s, e)




上一篇:查找文本模式 下一篇:快递查询API
0