问题描述
我希望能够检测不和谐用户何时发送 URL 链接,无论是视频、网站还是不和谐邀请,并保存链接,是否有任何预先存在的库?
I want to be able to detect when a discord user sends a URL link, whether it be a video, website, or discord invite, and to save the link, are there any pre-existing libraries?
推荐答案
Regex 是我最喜欢的解决方案.
Regex is my favourite solution for this.
def _match_url(url): regex = re.compile( "(([w]+:)?//)?(([dw]|%[a-fA-fd]{2,2})+(:([dw]|%[a-fA-fd]{2,2})+)?@)?([dw][-dw]{0,253}[dw].)+[w]{2,63}(:[d]+)?(/([-+_~.dw]|%[a-fA-fd]{2,2})*)*(?(&?([-+_~.dw]|%[a-fA-fd]{2,2})=?)*)?(#([-+_~.dw]|%[a-fA-fd]{2,2})*)?" ) if regex.match(url): return True else: return False