I need to extract the domain name from a string which is like "http://www.domain.com/bla324". The result should be "www.domain.com".
Any ideas on this?
You can simply use a regular expression :
var url = "http://www.domain.com/bla324",
match = url.match(/\/\/([^\/]+)\//)[1];
if (match) {
var host = match[1];
...
}
You may also use the dedicated and standard node package url :
var url = "http://www.domain.com/bla324",
urlObject = require('url').parse(url),
host = urlObject.host;
In the browser, I would use the a element :
var url = "http://www.domain.com/bla324",
a = document.createElement('a');
a.href = url;
var host = a.host;
In node, the package url like @dystroy said.