capturing multiple groups?

Darrell dgallion1 at yahoo.com
Sun Jul 22 16:03:50 EDT 2001


>>> re.findall("(12.)",s)
['12X', '12Y', '12Z']
>>> re.findall("(12[^1@]+)",s)
['12X', '12Y', '12Z']

And just for fun...
>>> ['12'+val for val in filter(len, s.replace('@','').replace('12','~').strip()
.split('~'))]
['12X', '12Y', '12Z']
>>>


--Darrell 


"Tom Baker" <bktoa23 at hotmail.com> wrote 
> What is the required syntax to match and save repeating groups?  ie.
> 
> Have:  @12X12Y12Z@
> Want:  ['12X' '12Y' '12Z']
> 
> My re of  re.compile("@(12.)*@") matches but only saves '12Z', and that is
> exactly what the manual says it should do!!!  I'm sure I did this sort of
> thing in Perl before but I've not been able to come across the correct
> python syntax.
> 
> Thanks in advance,
> Jim



More information about the Python-list mailing list