split string without removal of delimiter in python -
i need split string without removal of delimiter in python.
eg:
content = 'this 1 string big 2 need split 3 paragraph wise. 4 string 5 not formated string.' content = content.split('\s\d\s')
after getting this:
this\n string big\n need split it\n paragraph wise.\n string\n not formated string.
but want way:
this\n 1 string big\n 2 need split it\n 3 paragraph wise.\n 4 string\n 5 not formated string
you use re.split
forward lookahead:
import re re.split('\s(?=\d\s)',content)
resulting in:
['this', '1 string big', '2 need split it', '3 paragraph wise.', '4 string', '5 not formated string.']
this splits on spaces -- followed digit space.
Comments
Post a Comment