【发布时间】:2018-12-29 12:18:43
【问题描述】:
我正在处理这样的文本文件:
第 1 章
Lorem ipsum
dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
第02章
consectetur adipiscing
sed 做 eiusmod 时间
第03章
et dolore magna aliqua。
带有“chapter”、“Chapter”、“CHAPTER”等分隔符以及 1 或 2 位数字(“Chapter 1”或“Chapter 01”)。
我设法使用.open() 和.read() 在 Python 中打开和读取文件
mytext = myfile.read()
现在我需要拆分字符串,以获取“第 XX 章”的文本。
对于第 2 章,那就是:
consectetur adipiscing
sed 做 eiusmod 时间
我是 Python 新手,我读过关于 regex、match、map 或 split 的内容,但是……嗯……
(我正在写一个 Gimp Python-fu 插件,所以我使用 Gimp 中捆绑的 Python 版本,即 2.7.15)。
【问题讨论】:
标签: python string python-2.7 split