擅长:python、mysql、java
<p>您的正则表达式很接近,但是您可以将分隔符更改为使用<code>" by</code>和<code>on</code>。但是,您需要使用括号来捕获组。你知道吗</p>
<p>您可以这样使用正则表达式:</p>
<pre><code>" by (.+?) on
</code></pre>
<p><strong><a href="https://regex101.com/r/oN1uJ8/1" rel="nofollow">Working demo</a></strong></p>
<p><img src="https://www.debuggex.com/i/WeaW9dGrXAk4T3Cw.png" alt="Regular expression visualization"/></p>
<p>这个正则表达式背后的思想是使用一个简单的非reedy正则表达式捕获<code>" by</code>和<code>on</code>之间的内容。你知道吗</p>
<p>匹配信息</p>
<pre><code>MATCH 1
1. [43-58] `Luther Vandross`
</code></pre>
<p>代码</p>
<pre><code>import re
p = re.compile(ur'" by (.+?) on')
test_str = u"I'm listening to \"I Can Make It Better\" by Luther Vandross on Pandora #pandora http://t.co/ieDbLC393F.\n"
re.search(p, test_str)
</code></pre>