正则匹配URL地址

import re
u = "http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+"


def match_by_re(str):
    pattern = re.compile(u, re.S)
    res = pattern.findall(string=str)
    if res: return res[0]

 

posted @ 2019-02-26 16:27  Leslie-x  阅读(1711)  评论(0编辑  收藏  举报