我在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)
一切正常,我只需要在循环之前获得匹配的数量.