我正在用python阅读大量的文本
文本格式为:
blablabla
***** END HEADER ******
valid content
***** start footer *****
blablalba
我需要删除所有文本中的页眉和页脚,方法是删除所有字符串直到******结束页眉****以及在******开始页脚****之后的所有内容
任何帮助都将不胜感激
我已经试过了:
import re
chop = re.compile('(/.+)*** END HEADER *****', re.DOTALL)
data_chopped = chop.sub('', text_file)
但我一直得到一个错误:
sre_constants.error: multiple repeat at position
可能还有其他有效的方法,其中一种方法是尝试使用多个拆分:
结果:
相关问题 更多 >
编程相关推荐