擅长:python、mysql、java
<p>也许这有助于找到每个段落的标题和每一段的行。你知道吗</p>
<pre><code>text = """== Title1 == // Paragraph starts
.............
............. // Some texts
.............
End of Paragraph
===Title2 === // Paragraph starts
.............
............. // Some texts
.............
"""
import re
reg = re.compile(r'(?:[=]+\s*\w+\s*[=]+)')
for i in text.split('\n'):
if re.search(reg, i):
t = re.sub(r'=', '', i)
print('Title:', t.strip())
else:
print('line:', i.strip())
# Output like this
Title: Title1 // Paragraph starts
line: .............
line: ............. // Some texts
line: .............
line: End of Paragraph
Title: Title2 // Paragraph starts
line: .............
line: ............. // Some texts
line: .............
line:
</code></pre>