我想逐行處理一個字符串,但我想啓用多線支持。這是示例文本:Python:如何拆分線合併一些線
First line
Second line
{{{
these three lines
I want to process
together
}}}
Last Line
我想我曾經通過下列方式逐行處理它多以{{{
,終點開始在}}}
:
lines = [l for l in text.splitlines()]
print lines
眼下這段代碼輸出:
['First line', 'Second line', '{{{', 'these three lines', 'I want to process', 'together', '}}}', 'Last Line']
我想以某種方式使lines
包含以下內容:
['First line', 'Second line', 'these three lines I want to process together', 'Last Line']
或者更高級的例子
First Line
Second line
Third{{{line
fourth line
fifth}}}line
sixth line
在這種情況下,我想行包含
['First Line', 'Second line', 'Third', 'line fourth line fifth', 'line', 'sixth line']
嘗試迭代當前輸出,檢查'{{{',然後連接所有行,直到你到'}}}'。 – tburrows13