Help: Arbitrary number of groups in regex

Sean 'Shaleh' Perry shalehperry at attbi.com
Thu Aug 8 16:39:13 EDT 2002


On 08-Aug-2002 Jean-Philippe Côté wrote:
> 
> I apologize if this a common and/or stupid question (it probably is),
> but I can't figure it out.
> 
> I'm trying to write a regular expression pattern which can return
> an arbitrary number of groups, depending on the string on
> which is it applied.
> 
> For instance, if I do
>>>> import re
>>>> m = re.match("PATTERN", "abcde")
>>>> m.groups()
> I'd like to see
> ('a','b','c','d','e')
> 

>>> import re
>>> re.findall(r'(\w)', "abcde")
['a', 'b', 'c', 'd', 'e']





More information about the Python-list mailing list