0

Another noob question I would like to match the url without the http and and /

http://somesite.com/ ==> somesite.com

both for http and https

https://somesite.com/ ==> somesite.com

Apologize for the noob question

2 Answers 2

3

I would use urlparse instead

>>> import urlparse
>>> url = "http://somesite.com/"
>>> urlparse.urlparse(url).netloc
'somesite.com'
Sign up to request clarification or add additional context in comments.

Comments

1

I realize it is not regex, but you could use the urlparse (urllib.parse in 3) module: https://docs.python.org/2/library/urlparse.html

The first function they describe will give the netloc, which can be split appropriately.

#! /usr/bin/python

from urlparse import urlparse
url = 'http://stackoverflow.com/questions/28100042/python-simple-regex-get-url-name-without-http-and'
parsed = urlparse(url)
site = parsed.netloc
print site

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.