开发者

Python re.findall with groupdicts

开发者 https://www.devze.com 2023-03-01 04:04 出处:网络
I kind of wish that there were a version of re.findall that returned groupdicts instead of just groups. Am I mi开发者_StackOverflowssing some simple way to accomplish the same result?

I kind of wish that there were a version of re.findall that returned groupdicts instead of just groups. Am I mi开发者_StackOverflowssing some simple way to accomplish the same result?

Does anybody know of a reason that this function doesn't exist?


You could use the finditer() function. This will give you a sequence of match objects, so you can get the groupdict for each with:

[m.groupdict() for m in regex.finditer(search_string)]
0

精彩评论

暂无评论...
验证码 换一张
取 消