将PHP的preg_match_all转换为Python

2024-06-16 14:02:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我能用Python翻译一下PHP的preg_match_all('/(https?:\/\/\S+)/', $text, $links)吗?(ie)我需要获取数组中纯文本参数中存在的链接。


Tags: texthttps文本参数链接match数组links
1条回答
网友
1楼 · 发布于 2024-06-16 14:02:36

这样做:

import re
links = re.findall('(https?://\S+)', text)

如果计划多次使用,则可以考虑执行以下操作:

import re
link_re = re.compile('(https?://\S+)')
links = link_re.findall(text)

相关问题 更多 >