Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python re.findall with groupdicts

Tags:

python

regex

I kind of wish that there were a version of re.findall that returned groupdicts instead of just groups. Am I missing some simple way to accomplish the same result? (Does anybody know of a reason that this function doesn't exist?)

like image 966
cdleary Avatar asked Nov 01 '08 00:11

cdleary


1 Answers

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)]
like image 109
Brian Avatar answered Oct 05 '22 23:10

Brian