re.findall which returns a dict of named capturing groups?

后端 未结 4 1120
忘了有多久
忘了有多久 2020-12-04 15:12

Inspired by a now-deleted question; given a regex with named groups, is there a method like findall which returns a list of dict with the named cap

4条回答
  •  一生所求
    2020-12-04 15:54

    If you are using match :

    r = re.match('(?P[a-z]+)\s+(?P[a-z]+)', text)
    r.groupdict()
    

    documentation here

提交回复
热议问题