I need to write some javascript to strip the hostname:port part from a url, meaning I want to extract the path part only.
i.e. I want to write a function getPath(url
The window.location object has pathname, search and hash properties which contain what you require.
for this page
location.pathname = '/questions/441755/regular-expression-to-remove-hostname-and-port-from-url'
location.search = '' //because there is no query string
location.hash = ''
so you could use
var fullpath = location.pathname+location.search+location.hash