Newbie question about Re

MB ritm at gnet.tn
Tue Aug 24 15:05:23 CEST 1999


Hi

I just want to split a string of n x (p characters) into a list of
p_length strings using the Re module
Example: Assume p=5 the string '12345ABCDE12345IJKLM' must be split in
['12345','ABCDE','12345','IJKLM'']
The way I  find is to make a replace before splitting:

p=re.compile('(.{5,5})',re.DOTALL)
m=p.sub(r'\g<0>###','12345ABCDE12345IJKLM')
# I use ### as separator
re.split('###',m)
['12345', 'ABCDE', '12345', 'IJKLM', '']
# And I have to remove the trailing ''

But I don't like this too much.
Is there a better way?

Thanks






More information about the Python-list mailing list