擅长:python、mysql、java
<p>您也可以尝试regex方法:</p>
<pre><code>>>> print(s)
ID=s4k5jk
Date=8 December 1970
Title=crossing the atlantic on a tricycle
ID=f983
Date=22 December 1970
Title=Royal Episode 13
>>> fields = re.findall(r'ID=([\s\S]+?)\sDate=([\s\S]+?)\sTitle=([\s\S]+?)$', s, re.MULTILINE)
>>> fields
[('s4k5jk', '8 December 1970', 'crossing the atlantic on a tricycle'), ('f983', '22 December 1970', 'Royal Episode 13')]
>>>
</code></pre>
<p>注意,使用捕获组与<code>re.findall</code>完全一样!你知道吗</p>