python regular expression for domain names
Posted
by user230911
on Stack Overflow
See other posts from Stack Overflow
or by user230911
Published on 2010-04-13T04:35:09Z
Indexed on
2010/04/13
4:43 UTC
Read the original article
Hit count: 353
I am trying use the following regression to extract domain name from a text, but it just produce nothing, what's wrong with it? I don't know if this is suitable to ask this "fix code" question, maybe I should read more. I just want to save some time. Thanks
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")
I want the output to be google.com
© Stack Overflow or respective owner