拆分字符串而不删除python中的定界符

强尼

我需要在不删除Python中分隔符的情况下拆分字符串。

例如:

content = 'This 1 string is very big 2 i need to split it 3 into paragraph wise. 4 But this string 5 not a formated string.'
content = content.split('\s\d\s') 

在此之后,我得到的是这样的:

This\n
string is very big\n
i need to split it\n
into paragraph wise.\n
But this string\n
not a formated string.

但我想这样:

This\n
1 string is very big\n
2 i need to split it\n
3 into paragraph wise.\n
4 But this string\n
5 not a formated string
约翰·科尔曼

您可以re.split与前瞻性配合使用

import re
re.split('\s(?=\d\s)',content)

导致:

['This', '1 string is very big', '2 i need to split it', '3 into paragraph wise.', '4 But this string', '5 not a formated string.']

这会在空格上分割-但仅是那些紧跟着一个数字然后是另一个空格的空格。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Python字符串拆分模式,不删除定界符

在Swift中拆分字符串而不删除定界符

将字符串拆分为数组而不删除定界符?

将字符串拆分为数组而不删除定界符ruby

Java:使用正则表达式拆分字符串而不删除定界符

JS / TS用定界符分割字符串而不删除定界符

删除bash中由多字符定界符拆分的字符串的特定部分

删除定界符中的字符串部分

python将字符串拆分为多个定界符并放入字典中

如何在python中拆分字符串并使用定界符获取结果?

拆分字符串保留一些定界符,但删除另一个定界符

在python中的定界符'\'处分割字符串

Python Pandas:删除字符串中定界符后的所有内容

在定界符处拆分python字符串,但使用特定的字符串

Python split()而不删除定界符

使用多个定界符快速拆分字符串

如何拆分字符串,但还要保留定界符?

使用保存定界符将字符串按多个定界符进行拆分

使用默认定界符与用户定义定界符进行字符串拆分

JavaScript字符串使用多个定界符进行拆分,同时保留定界符

如何在bash中的多字符定界符上拆分字符串?

python通过定界符拆分字符串,只有它在引号之外

Python-按定界符出现次数拆分大字符串

python根据模式拆分长输出字符串(无定界符)

Python使用定界符拆分整数和字符串(混合)列表?

如何拆分没有定界符但固定位数的字符串-python

如何在Java中拆分字符串并保留定界符?

如何在列表中存储的多个定界符上拆分字符串?

通过定界符将字符串批量拆分为文件中的新行