複数行の文字列から、特定の文字 (この場合は開き括弧) を含む最初の行までのすべての行を解析したいと考えています。
s = """Here are the lines
of text that i want.
The first line with <tags> and everything
after should be stripped."""
s1 = s[:s.find('<')]
s2 = s1[:s.rfind('\n')]
print s2
結果:
ここに
私が欲しいテキストの行があります。
との最初の行
私が探しているもの:
ここに
私が欲しいテキストの行があります。