import re
def splittext(text, split_by):
'''the regex will take a string and create groupings of n-characters plus a final grouping of any remainder. if no remainder is desired, the |.+ can be removed'''
return re.findall(r".{%d}|.+" % split_by, text)
ret = splittext("HELLOWORLD!", 2)
print "\n".join(ret)
some sample output
>>> re.findall(r".{2}",a)
['HE', 'LL', 'OW', 'OR', 'LD']
>>> re.findall(r".{2}|.{1}",a)
['HE', 'LL', 'OW', 'OR', 'LD', '!']
>>> re.findall(r".{2}|.*",a)
['HE', 'LL', 'OW', 'OR', 'LD', '!', '']
>>> re.findall(r".{2}|.+",a)
['HE', 'LL', 'OW', 'OR', 'LD', '!']
>>> print "\n".join(_)
HE
LL
OW
OR
LD
!
>>>