如何检查邮件内容中的超链接(最好通过Discord.py) [英] How to check for hyperlinks in the contents of a message (through Discord.py preferably)
本文介绍了如何检查邮件内容中的超链接(最好通过Discord.py)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望能够检测出不和谐的用户何时发送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 is my favourite solution for this.
def _match_url(url):
regex = re.compile(
"(([\w]+:)?//)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,63}(:[\d]+)?(/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?"
)
if regex.match(url):
return True
else:
return False
这篇关于如何检查邮件内容中的超链接(最好通过Discord.py)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文