简体   繁体   English

Python正则表达式Findall

[英]Python Regular Expression Findall

I'm trying to find up to the top level domain information. 我正在尝试查找顶级域名信息。

If I were to search " https://testwebsite.com.au/folders/viewforum.php?f=1556n " I only want my expression to find " https://testwebsite.com.au " 如果我要搜索“ https://testwebsite.com.au/folders/viewforum.php?f=1556n ”,我只希望我的表达式查找“ https://testwebsite.com.au

I'm using the following expression: 我正在使用以下表达式:

urlRegex = re.compile(r'''( (https?|sftp|ftp|file)://[-a-zA-Z0-9+&@#/%?
           =~_|!:,.;'"*$()]*[a-zA-Z0-9+&@#/%=~_|]   )''', re.VERBOSE)

If you want to be strict and correct, use a real URL parser. 如果要严格和正确,请使用真实的URL解析器。 If you're looking for something quick and dirty that will work for 99% of the URLs you'll find, how about: 如果您正在寻找可用于99%的URL的快速而又肮脏的东西,该如何做:

urlRegex = re.compile(r'([a-zA-Z]+://[^/\s]+)')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM