简体   繁体   中英

Python re.findall with groupdicts

I kind of wish that there were a version of re.findall that returned groupdict s instead of just group s. Am I missing 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)]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM