将PHP的preg_match_all翻译为Python
问题描述:
我可以在Python中翻译PHP的preg_match_all('/(https?:\/\/\S+)/', $text, $links)
吗? (ie)我需要获取数组中的纯文本参数中的链接。将PHP的preg_match_all翻译为Python
答
这将做到这一点:
import re
links = re.findall('(https?://\S+)', text)
如果你打算使用这个多次比你可以考虑这样做:
import re
link_re = re.compile('(https?://\S+)')
links = link_re.findall(text)