擅长:python、mysql、java
<p>查看python<code>re</code>模块。在</p>
<p>例如,取<a href="http://daringfireball.net/2010/07/improved_regex_for_matching_urls" rel="nofollow">John Gruber's URL regex pattern</a>并将其与<a href="http://daringfireball.net/misc/2010/07/url-matching-regex-test-data.text" rel="nofollow">his data set</a>匹配,您可以做类似于。。。在</p>
<pre><code>giant_regex = r'''(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))'''
output_with_links = re.sub(giant_regex, r'<a href="\1">\1</a>', source_html)
</code></pre>
<p>不幸的是,这将捕获不需要转换的实际链接,但现在您的问题是找到正确的regex(如果您查找的话,我肯定已经在网上记录过了)。python和django部分已经完成。在</p>