You don't even need regex.

def split_seq(seq,size): # this is sort of the inverse of flatten # Source: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/425044 return [seq[i:i+size] for i in range(0, len(seq), size)] line = '123456789123456789' print split_seq(line,3)


Will that work for you?



[EMAIL PROTECTED] wrote:
hi
how can i use regexp to group these digits into groups of 3?

eg
line 123456789123456789

i have :

pat = re.compile("line\s+(\d{3})" , re.M|re.DOTALL)

but this only gives the first 3. I also tried

"line\s+(\d{3})+"
but also not working.
I need output to be ['123' ,'456','789', '123','456','789', .....]
thanks.


--
Shane Geiger
IT Director
National Council on Economic Education
[EMAIL PROTECTED]  |  402-438-8958  |  http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy

begin:vcard
fn:Shane Geiger
n:Geiger;Shane
org:National Council on Economic Education (NCEE)
adr:Suite 215;;201 N. 8th Street;Lincoln;NE;68508;United States
email;internet:[EMAIL PROTECTED]
title:IT Director
tel;work:402-438-8958
x-mozilla-html:FALSE
url:http://www.ncee.net
version:2.1
end:vcard

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to