小编yas*_*ein的帖子

用于域名的python正则表达式

我正在尝试使用以下正则表达式从文本中提取域名,但它只是产生什么,它有什么问题?我不知道这是否适合问这个"修复代码"问题,也许我应该阅读更多.我只想节省一些时间.谢谢

pat_url = re.compile(r'''

            (?:https?://)*

            (?:[\w]+[\-\w]+[.])*

            (?P<domain>[\w\-]*[\w.](com|net)([.](cn|jp|us))*[/]*)

            ''')

print re.findall(pat_url,"http://www.google.com/abcde")
Run Code Online (Sandbox Code Playgroud)

我希望输出为google.com

python regex dns url

3
推荐指数
1
解决办法
6168
查看次数

标签 统计

dns ×1

python ×1

regex ×1

url ×1