用于域名的python正则表达式

yas*_*ein 3 python regex dns url

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

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

Amb*_*ber 7

不要使用正则表达式.请改用urlparse标准库.它更直接,更容易阅读/维护.

http://docs.python.org/library/urlparse.html