正则表达式匹配域名

问题描述 投票:0回答:2

我的网址似乎是这样

https://inet.detik.com/cyberlife/d-4969020/jeff-bezos-jadi-orang-terkaya-sejagat-2020-bill-gates-kalah?tag_from=wp_beritautama&_ga=2.213088788.187118190.1586303591-856146141.1581847069

https://www.regexpal.com/?fam=93928

https://tekno.tempo.co/read/1329116/harimau-sumatera-ditemui-di-hutan-produksi-tapanuli-selatan

http://stackoverflow.com/posts/61091339/edit

我如何在正则表达式中匹配它们:

inet.detik.com

www.regexpal.com

tekno.tempo.co

stackoverflow.com

python regex
2个回答
0
投票

(https?:\/\/)([^\/]+)\/

Example matches


0
投票

您还可以在库中使用内置的正则表达式,而不用编写自己的正则表达式。

Python3中>

from urllib.parse import urlparse
urlparse('https://www.regexpal.com/?fam=93928').netloc

输出:

'www.regexpal.com'
© www.soinside.com 2019 - 2024. All rights reserved.