【问题标题】:Translating PHP’s preg_match_all to Python将 PHP 的 preg_match_all 翻译成 Python
【发布时间】:2010-10-05 16:53:56
【问题描述】:

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

【问题讨论】:

    标签: php python regex


    【解决方案1】:

    这样就可以了:

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

    如果您打算多次使用此功能,则可以考虑这样做:

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

    【讨论】:

      猜你喜欢
      • 2010-11-07
      • 2017-10-12
      • 1970-01-01
      • 1970-01-01
      • 2012-07-22
      • 1970-01-01
      • 2020-08-11
      • 2020-03-12
      • 1970-01-01
      相关资源
      最近更新 更多