python 正则表达式篇 - finditer 用法

代码

#!/usr/bin/env Python3
# -*- coding: utf-8 -*-
# @Software: PyCharm
# @virtualenv:workon
# @contact: contact information
# @Desc:finditer
__author__ = '未昔/AngelFate'
__date__ = '2019/8/22 19:58'


def re_finditer(con=''):
    """
     finditer(string[, pos[, endpos]]) | re.finditer(pattern, string[, flags]):
        搜索string,返回一个顺序访问每一个匹配结果(Match对象)的迭代器。
        :return:
    """
    import re

    if len(con)>0:
        p = re.compile(r'\d+')
        for m in p.finditer(con):
            print(m.group(), end="")


if __name__ == '__main__':
    con = 'one1two2three3four4'
    print(re_finditer(con))

结果:

D:\import\python3.7\python.exe "E:/python/Study/小经验/python正则表达式篇 - finditer用法.py"
1234None

Process finished with exit code 0