相关疑难解决方法(0)

正则表达式匹配数

我在re模块中使用finditer-function来匹配某些东西,一切正常.

现在我需要找出我有多少匹配,是否可以在没有循环遍历迭代器两次的情况下?(一个找出计数,然后是真实的迭代)

编辑:根据要求,一些代码:

imageMatches = re.finditer("<img src\=\"(?P<path>[-/\w\.]+)\"", response[2])
# <Here I need to get the number of matches>
for imageMatch in imageMatches:
    doStuff
Run Code Online (Sandbox Code Playgroud)

一切正常,我只需要在循环之前获得匹配的数量.

python regex

59
推荐指数
5
解决办法
8万
查看次数

标签 统计

python ×1

regex ×1