python:如何在一次搜索中找到\r\n\r\n
我必须根据python:如何在一次搜索中找到\r\n\r\n,python,regex,string,Python,Regex,String,我必须根据\r\n\r\n 我需要灵活性,这样行就可以以\r\n\r\n或\n\n结尾 如何分割文本 添加的示例: \===================FILE BEGIN========================================== name: about title: About publish: True order: -1 \r\n \r\n **example.com** is a example website provides the lat
\r\n\r\n
我需要灵活性,这样行就可以以\r\n\r\n
或\n\n
结尾
如何分割文本
添加的示例:
\===================FILE BEGIN==========================================
name: about
title: About
publish: True
order: -1
\r\n
\r\n
**example.com** is a example website provides the latest examples in organized way.
Blah blah blah....
Blah blah blah....
Blah blah blah....
\===================File END==========================================
第一部分是我的头(yaml格式),用于文件标识,第二部分是标记文本
import re
linend = re.compile(r'\r\n\r\n|\n\n')
s = 'an example\n\nstring\n\nhere'
print linend.split(s, 1)
s = 'another\r\n\r\nexample\r\n\r\nhere'
print linend.split(s, 1)
印刷品:
['an example', 'string\n\nhere']
['another', 'example\r\n\r\nhere']
根据要求。正则表达式模式
“\r\n\r\n | \n\n”
应该可以工作。只需使用re.split
或Regex.split
并设置maxslit=1
您能展示一些代码示例吗?