Answer the question
In order to leave comments, you need to log in
How to strip everything from a URL except the domain using REGEXP?
To get name.net
............................................... ........
Answer the question
In order to leave comments, you need to log in
What programming language do you need code for? In PHP, for example, this is done like this:
And here is an example for the front-end in javascript:
function cleanUp(url) {
var url = $.trim(url);
if(url.search(/^https?\:\/\//) != -1)
url = url.match(/^https?\:\/\/([^\/?#]+)(?:[\/?#]|$)/i, "");
else
url = url.match(/^([^\/?#]+)(?:[\/?#]|$)/i, "");
return url[1];
}
alert(cleanUp(' http://www.google.com/about.html'));
alert(cleanUp(' www.google.com/about.html'));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question