Help: Arbitrary number of groups in regex

Carl Banks imbosol at vt.edu
Thu Aug 8 22:59:41 CEST 2002


"Jean-Philippe C?t?" wrote:
> The way I undestand "(\w)*" is <<match a single alphanumeric
> character, put in into a group, return that group and repeat as
> long a you can>>, but that doesn't work:
>>>> m = re.match("(\w)*", "abcde")
>>>> m.groups()
> ('e',)
>>>>
> 
> Does anybody know what the PATTERN should be ?

I don't believe it's possible.  Perhaps it should be.  If all you want
to do is split a string into a sequence of characters, just do this:

>>> tuple("abcde")
('a', 'b', 'c', 'd', 'e')



-- 
CARL BANKS
http://www.aerojockey.com



More information about the Python-list mailing list