【发布时间】:2010-10-05 16:53:56
【问题描述】:
我可以翻译一下 Python 中的 PHP 的 preg_match_all('/(https?:\/\/\S+)/', $text, $links) 吗? (即)我需要在数组中获取纯文本参数中存在的链接。
【问题讨论】:
我可以翻译一下 Python 中的 PHP 的 preg_match_all('/(https?:\/\/\S+)/', $text, $links) 吗? (即)我需要在数组中获取纯文本参数中存在的链接。
【问题讨论】:
这样就可以了:
import re
links = re.findall('(https?://\S+)', text)
如果您打算多次使用此功能,则可以考虑这样做:
import re
link_re = re.compile('(https?://\S+)')
links = link_re.findall(text)
【讨论】: