Extract URL-parts

by John Wick

JavaScript

var url = 'http://mysite.com/section-with-dashes/howboutnow';
var section = url.match(/^http[s]?:\/\/.*?\/([a-zA-Z-_]+).*$/)[1];
//console.log(section);

var url = "http://www.domain.com/path/to/something?query#fragment";
var url = "http://abc.net";
var exp = url.split(/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/);

console.log(exp[4]);