开发者

Translating PHP’s preg_match_all to Python

开发者 https://www.devze.com 2023-01-19 06:32 出处:网络
Can I have a translation of PHP’s preg_match_all(\'/(https?:\\/\\/\\S+)/\', $text, $link开发者_运维技巧s) in Python, please? (ie) I need to get the links present in the plain text argument in an arra

Can I have a translation of PHP’s preg_match_all('/(https?:\/\/\S+)/', $text, $link开发者_运维技巧s) in Python, please? (ie) I need to get the links present in the plain text argument in an array.


This will do it:

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

If you plan to use this multiple times than you can consider doing this:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号