Ok how do i use regex to remove http AND/OR www just to get http://www.domain.com/ into domain.com
Assume x as any kind of TLD or cTLD
Input example:
Output:
domain.x
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you really want to use regular expressions instead of
urlparse()or splitting the string:The regular expression might a bit simplistic, but works. It’s also not replacing, but I think getting the domain out is easier.
To support domains like ‘co.uk’, one can do the following:
(‘google’, ‘co.uk’)
So you got to check the result for domains like ‘co.uk’, and join the result again in such a case. Normal domains should work OK. I could not make it work when you have multiple subdomains.
One-liner without regular expressions or fancy modules: