Python regular expressions - how to capture multiple groups from a wildcard expression?

John B picture John B · Jan 21, 2009 · Viewed 20.3k times · Source

I have a Python regular expression that contains a group which can occur zero or many times - but when I retrieve the list of groups afterwards, only the last one is present. Example:

re.search("(\w)*", "abcdefg").groups()

this returns the list ('g',)

I need it to return ('a','b','c','d','e','f','g',)

Is that possible? How can I do it?

Answer

Douglas Leeder picture Douglas Leeder · Jan 21, 2009
re.findall(r"\w","abcdefg")