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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

android - CoordinatorLayout, FAB and container layout conflict -