擅长:python、mysql、java
<p>可以使用<a href="https://docs.python.org/2/library/re.html#re.sub" rel="nofollow noreferrer">re.sub()</a>将所有链接替换为空字符串:</p>
<pre><code>>>> import re
>>> pattern = re.compile('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+')
>>> s = 'Mi grupo favorito de CRIMINALISTICA. Ultima clase de cuatrimestre http://t.co/Ad2oWDNd4u'
>>> pattern.sub('', s)
'Mi grupo favorito de CRIMINALISTICA. Ultima clase de cuatrimestre '
</code></pre>
<p>它将替换字符串中任何位置的所有链接:</p>
^{pr2}$
<p>正则表达式取自此线程:</p>
<ul>
<li><a href="https://stackoverflow.com/questions/6883049/regex-to-find-urls-in-string-in-python">Regex to find urls in string in Python</a></li>
</ul>