Python re.findall with groupdicts

cdl*_*ary 11 python regex

我有点希望有一个版本的re.findall返回groupdicts而不是groups.我错过了一些简单的方法来完成相同的结果吗?(有人知道这个功能不存在的原因吗?)

Bri*_*ian 25

您可以使用finditer()函数.这将为您提供一系列匹配对象,因此您可以为每个对象获取groupdict:

[m.groupdict() for m in regex.finditer(search_string)]
Run Code Online (Sandbox Code Playgroud)