擅长:python、mysql、java
<p>您可以使用这个简单的regex <code>'.[:|].'</code></p>
<pre><code>import re
text1='If I controlled the internet | Rives '
text2='Life at 30,000 feet | Richard Brandson'
text3='larry brilliant : A surprising idea for "solving" climate change'
text = (text1, text2, text3)
for item in text:
title, speaker = re.split('.[:|].', item)
print('title:', title, ' - Speaker:', speaker)
</code></pre>
<p>输出:</p>
<pre><code>title: If I controlled the internet - Speaker: Rives
title: Life at 30,000 feet - Speaker: Richard Brandson
title: larry brilliant - Speaker: A surprising idea for "solving" climate change
</code></pre>
<p>注意最后一个:)</p>