Newbie question about Re

Mike Fletcher mcfletch at
Tue Aug 24 16:58:41 CEST 1999

Well, here's my take on a "better way"... I don't see why you would want to
use the RE module when you aren't doing any pattern matching...

def splitlen( instring, desiredlength):
	temp = []
	current = 0
	lenstr = len( instring)
	while current < lenstr:
		newcurrent = current+desiredlength
		temp.append( instring[current:newcurrent] )
		current = newcurrent
	return temp

I haven't even tested this for correctness, but I think it's close to

Hope this helps,

-----Original Message-----
From: python-list-request at [mailto:python-list-request at]On
Behalf Of MB
Sent: August 24, 1999 9:05 AM
To: python-list at
Subject: Newbie question about Re


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
The way I  find is to make a replace before splitting:

# I use ### as separator
['12345', 'ABCDE', '12345', 'IJKLM', '']
# And I have to remove the trailing ''

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


More information about the Python-list mailing list