I want to extract the base name from a image URL in Javascript. Would somebody care to give me a a hand on the Regex?
The rule would be:
return ever
When you have access to a DOM, you can use the native HTMLHyperlinkElementUtils
properties of an tag:
function urlInfo (url) {
var props = 'hash host hostname href origin password pathname port protocol username search';
if (!window.urlInfoAnchorElement)
window.urlInfoAnchorElement = document.createElement('a');
urlInfoAnchorElement.href = url;
return props.split(' ').reduce(function (m, v, i) {
m[v] = urlInfoAnchorElement[v]; return m;
}, {});
}
// Example:
urlInfo('http://localhost:4000/guidelines/7yQxvndK?get=sup&love=1#oiwjef');
/* => {
hash: "#oiwjef"
host: "localhost:4000"
hostname: "localhost"
href: "http://localhost:4000/guidelines/7yQxvndK?get=sup&love=1#oiwjef"
origin: "http://localhost:4000"
password: ""
pathname: "/guidelines/7yQxvndK"
port: "4000"
protocol: "http:"
search: "?get=sup&love=1"
} */