我有一个包含以下内容的字符串(多行):
"Name=My name
Address=......
\##### To extract from here ####
line 1
line 2
line 3
\##### To extract till here ####
close"
如何提取 "##### To extract *"
字符串之间的行,包括模式?
输出应如下所示:
\##### To extract from here ####
line 1
line 2
line 3
最佳答案
pat = re.compile('\\\\##### To extract from here ####'
'.*?'
'(?=\\\\##### To extract till here ####)',
re.DOTALL)
或
pat = re.compile(r'\\##### To extract from here ####'
'.*?'
r'(?=\\##### To extract till here ####)',
re.DOTALL)
关于python - 如何在 python 中使用 re 模块匹配模式之间的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5088821/