假设我有这样一个文档:
document = ["This is a document\nwhich has to be splitted\nOK/Right?"]
我希望在遇到“\n”或“/”时拆分此文档(用于开始)。你知道吗
因此,上述文件应转换为以下文件:
document = ["This is a document", "which has to be splitted", "OK", "Right?"]
我该怎么做?你知道吗
请记住,文本中可能有其他特殊字符等,我现在不想删除它们。你知道吗
Tags:
使用
re.split()
可能是最好的解决方案。你知道吗没有正则表达式的替代解决方案:
使用
re
根据多个字符或字符组合拆分文本字符串:它生成请求的字符串:
['This is a document', 'which has to be splitted', 'OK', 'Right?']
您可以使用
re.split()
:相关问题 更多 >
编程相关推荐